summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Loupmon <vincentloupmon@gmail.com>2016-03-09 12:38:22 +0100
committerVincent Loupmon <vincentloupmon@gmail.com>2016-03-09 12:38:22 +0100
commite241dbeba4bd8e4f9cd2786d76697afd6057e406 (patch)
tree1d55f8d371fc9490fb3e8cba592dac24d3dc9960
parent2fb476aaf6b084bdf4847db867d3d44811934c2b (diff)
Changed RAM calculation formula.
Former : MemTotal - MemAvailable New : (MemTotal - MemFree) - (Buffers + Cached)
-rw-r--r--slstatus.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/slstatus.c b/slstatus.c
index cd2def6..331a345 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -162,7 +162,7 @@ char *
get_ram_usage()
{
int ram_perc;
- long total, free, available;
+ long total, free, buffers, cached;
FILE *fp;
/* open meminfo file */
@@ -174,13 +174,14 @@ get_ram_usage()
/* read the values */
fscanf(fp, "MemTotal: %ld kB\n", &total);
fscanf(fp, "MemFree: %ld kB\n", &free);
- fscanf(fp, "MemAvailable: %ld kB\n", &available);
+ fscanf(fp, "MemAvailable: %ld kB\nBuffers: %ld kB\n", &buffers, &buffers);
+ fscanf(fp, "Cached: %ld kB\n", &cached);
/* close meminfo file */
fclose(fp);
/* calculate percentage */
- ram_perc = 100 * (total - available) / total;
+ ram_perc = 100 * ((total - free) - (buffers + cached)) / total;
/* return ram_perc as string */
return smprintf("%d%%",ram_perc);