]> mj.ucw.cz Git - ywho.git/commitdiff
Do not forget "Cached:" in /proc/meminfo when calculating free memory
authorMartin Mares <mj@ucw.cz>
Fri, 20 Aug 2010 15:04:44 +0000 (17:04 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 20 Aug 2010 15:04:44 +0000 (17:04 +0200)
ywho.c

diff --git a/ywho.c b/ywho.c
index c44cca60b7d01ca9f200e124c6990e232307c4af..ecfc3ca73a8dea88d9db2cf9cf7f52a0f05b8592 100644 (file)
--- a/ywho.c
+++ b/ywho.c
@@ -333,7 +333,7 @@ dispsys(void)
     }
   if (f = fopen("/proc/meminfo", "r"))
     {
-      int free, buffers, stotal, sfree;
+      int free, buffers, cached, stotal, sfree;
       free = buffers = stotal = sfree = 0;
       while (fgets(line, 256, f))
        {
@@ -341,13 +341,15 @@ dispsys(void)
            sscanf(line+8, "%d", &free);
          else if (!strncmp(line, "Buffers:", 8))
            sscanf(line+8, "%d", &buffers);
+         else if (!strncmp(line, "Cached:", 7))
+           sscanf(line+7, "%d", &cached);
          else if (!strncmp(line, "SwapTotal:", 10))
            sscanf(line+10, "%d", &stotal);
          else if (!strncmp(line, "SwapFree:", 9))
            sscanf(line+9, "%d", &sfree);
        }
       printf(", free ");
-      memory(1024*(free+buffers));
+      memory(1024*(free+buffers+cached));
       printf(" of RAM");
       if (stotal != sfree)
        {