wmmemfree: Parse modern /proc/meminfo
This commit is contained in:
parent
e98be23914
commit
08a8a6a70e
|
@ -34,10 +34,14 @@ void mem_getfree()
|
||||||
perror("/proc/meminfo");
|
perror("/proc/meminfo");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
while(fgetc(file)!='\n'){}
|
fscanf(file, "MemTotal: %lld kB MemFree: %lld kB MemAvailable: %*d kB "
|
||||||
fscanf(file, "%*s %Ld %Ld %Ld %Ld %Ld %Ld",
|
"Buffers: %lld kB Cached: %lld kB",
|
||||||
&mem_total, &mem_used, &mem_free, &mem_shared, &mem_buffers, &mem_cached);
|
&mem_total, &mem_free, &mem_buffers, &mem_cached);
|
||||||
fscanf(file, "%*s %Ld %Ld %Ld",
|
for (int i = 0; i < 10; i++) {
|
||||||
&swp_total, &swp_used, &swp_free);
|
while (fgetc(file) != '\n') {}
|
||||||
|
}
|
||||||
|
fscanf(file, "SwapTotal: %lld kB SwapFree: %lld kB", &swp_total, &swp_free);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
mem_used = mem_total - mem_free;
|
||||||
|
swp_used = swp_total - swp_free;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue