Shows "Use memory" as 'free' command line.
authorCarles Pina i Estany <carles@pina.cat>
Sun, 6 Jan 2019 22:45:18 +0000 (22:45 +0000)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Sun, 13 Jan 2019 21:25:38 +0000 (23:25 +0200)
'free' command line utility counts SReclaimable as not used. Now lxtask
does the same.

src/xfce-taskmanager-linux.c

index dd490c1..2b2a186 100644 (file)
@@ -263,6 +263,11 @@ gboolean get_system_status (system_status *sys_stat)
     file = fopen ("/proc/meminfo", "r");
     if(!file) return FALSE;
     reach=0;
+
+    /* Same approach as 'free' from procps-3.3.12: mem_cached
+     * is Cached+SReclaimable (see proc/sysinfo.c line 707 */
+    sys_stat->mem_cached = 0;
+
     while (fgets (buffer, 100, file) != NULL)
     {
         if(!strncmp(buffer,"MemTotal:",9))
@@ -270,10 +275,12 @@ gboolean get_system_status (system_status *sys_stat)
         else if(!strncmp(buffer,"MemFree:",8))
             sys_stat->mem_free=atoi(buffer+9),reach++;
         else if(!strncmp(buffer,"Cached:",7))
-            sys_stat->mem_cached=atoi(buffer+8),reach++;
+            sys_stat->mem_cached+=atoi(buffer+8),reach++;
+       else if(!strncmp(buffer,"SReclaimable:", 13))
+           sys_stat->mem_cached+=atoi(buffer+14),reach++;
         else if(!strncmp(buffer,"Buffers:",8))
             sys_stat->mem_buffered=atoi(buffer+9),reach++;
-        if(reach==4) break;
+        if(reach==5) break;
     }
     fclose (file);