diff options
Diffstat (limited to 'free.c')
-rw-r--r-- | free.c | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -23,15 +23,33 @@ | |||
23 | 23 | ||
24 | #include "internal.h" | 24 | #include "internal.h" |
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <sys/sysinfo.h> | ||
26 | 27 | ||
27 | 28 | #define DIVISOR 1024 | |
28 | #if ! defined BB_FEATURE_USE_PROCFS | ||
29 | #error Sorry, I depend on the /proc filesystem right now. | ||
30 | #endif | ||
31 | |||
32 | extern int free_main(int argc, char **argv) | 29 | extern int free_main(int argc, char **argv) |
33 | { | 30 | { |
34 | char *cmd[] = { "cat", "/proc/meminfo", "\0" }; | 31 | struct sysinfo info; |
32 | sysinfo(&info); | ||
33 | info.totalram/=DIVISOR; | ||
34 | info.freeram/=DIVISOR; | ||
35 | info.totalswap/=DIVISOR; | ||
36 | info.freeswap/=DIVISOR; | ||
37 | info.sharedram/=DIVISOR; | ||
38 | info.bufferram/=DIVISOR; | ||
39 | |||
40 | |||
41 | printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free", | ||
42 | "shared", "buffers"); | ||
43 | |||
44 | printf("%6s%13ld%13ld%13ld%13ld%13ld\n", "Mem:", info.totalram, | ||
45 | info.totalram-info.freeram, info.freeram, | ||
46 | info.sharedram, info.bufferram); | ||
47 | |||
48 | printf("%6s%13ld%13ld%13ld\n", "Swap:", info.totalswap, | ||
49 | info.totalswap-info.freeswap, info.freeswap); | ||
35 | 50 | ||
36 | exit(cat_main(3, cmd)); | 51 | printf("%6s%13ld%13ld%13ld\n", "Total:", info.totalram+info.totalswap, |
52 | (info.totalram-info.freeram)+(info.totalswap-info.freeswap), | ||
53 | info.freeram+info.freeswap); | ||
54 | exit(TRUE); | ||
37 | } | 55 | } |