File: free.c

package info (click to toggle)
libgtop2 2.38.0-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,944 kB
  • sloc: ansic: 25,286; sh: 7,044; makefile: 416; perl: 268; xml: 179; sed: 16
file content (44 lines) | stat: -rw-r--r-- 952 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <glibtop.h>
#include <glibtop/mem.h>
#include <glibtop/swap.h>

#include <glib.h>
#include <unistd.h>

static unsigned mb(guint64 n)
{
        return n >> 20;
}

int main(int argc, char **argv)
{
        glibtop_mem mem;
        glibtop_swap swap;

	glibtop_init();

        glibtop_get_mem(&mem);
        glibtop_get_swap(&swap);

        printf("              total        used        free      shared  buff/cache   available\n");

        printf("%-7s %11u %11u %11u %11u %11u %11u\n",
               "Mem:",
                mb(mem.total),
                mb(mem.used - mem.buffer - mem.cached),
                mb(mem.free),
                mb(mem.shared),
                mb(mem.buffer + mem.cached),
                mb(mem.total - mem.user));

        printf("%-7s %11u %11u %11u\n",
               "Swap:",
                mb(swap.total),
                mb(swap.used),
                mb(swap.free));

	glibtop_close();

	return 0;
}