diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-12 01:56:44 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-12 01:56:44 +0200 |
commit | 7bfbbd434a6f435b0287cd25406927c630b03f68 (patch) | |
tree | ce95cd55e47356170d91a2a832cc4311e7062a53 | |
parent | 733f26f40708e0a4a2eb2475c446ae6a8e31f477 (diff) | |
download | busybox-w32-7bfbbd434a6f435b0287cd25406927c630b03f68.tar.gz busybox-w32-7bfbbd434a6f435b0287cd25406927c630b03f68.tar.bz2 busybox-w32-7bfbbd434a6f435b0287cd25406927c630b03f68.zip |
free: more compatible output. +16 bytes. Closes bug 2383.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | procps/free.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/procps/free.c b/procps/free.c index 473d70be8..db70712cf 100644 --- a/procps/free.c +++ b/procps/free.c | |||
@@ -53,29 +53,41 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM)) | |||
53 | info.bufferram *= mem_unit; | 53 | info.bufferram *= mem_unit; |
54 | } | 54 | } |
55 | 55 | ||
56 | printf(" %13s%13s%13s%13s%13s\n", | 56 | printf(" %13s%13s%13s%13s%13s\n", |
57 | "total", | 57 | "total", |
58 | "used", | 58 | "used", |
59 | "free", | 59 | "free", |
60 | "shared", "buffers" /* swap and total don't have these columns */ | 60 | "shared", "buffers" /* swap and total don't have these columns */ |
61 | /* procps version 3.2.8 also shows "cached" column, but | ||
62 | * sysinfo() does not provide this value, need to parse | ||
63 | * /proc/meminfo instead and get "Cached: NNN kB" from there. | ||
64 | */ | ||
61 | ); | 65 | ); |
62 | printf("%6s%13lu%13lu%13lu%13lu%13lu\n", "Mem:", | 66 | #define FIELDS_5 "%13lu%13lu%13lu%13lu%13lu\n" |
67 | #define FIELDS_3 (FIELDS_5 + 2*5) | ||
68 | #define FIELDS_2 (FIELDS_5 + 3*5) | ||
69 | printf("Mem: "); | ||
70 | printf(FIELDS_5, | ||
63 | info.totalram, | 71 | info.totalram, |
64 | info.totalram - info.freeram, | 72 | info.totalram - info.freeram, |
65 | info.freeram, | 73 | info.freeram, |
66 | info.sharedram, info.bufferram | 74 | info.sharedram, info.bufferram |
67 | ); | 75 | ); |
76 | /* Show alternate, more meaningful busy/free numbers by counting | ||
77 | * buffer cache as free memory (make it "-/+ buffers/cache" | ||
78 | * if/when we add support for "cached" column): */ | ||
79 | printf("-/+ buffers: "); | ||
80 | printf(FIELDS_2, | ||
81 | info.totalram - info.freeram - info.bufferram, | ||
82 | info.freeram + info.bufferram | ||
83 | ); | ||
68 | #if BB_MMU | 84 | #if BB_MMU |
69 | printf("%6s%13lu%13lu%13lu\n", "Swap:", | 85 | printf("Swap:"); |
86 | printf(FIELDS_3, | ||
70 | info.totalswap, | 87 | info.totalswap, |
71 | info.totalswap - info.freeswap, | 88 | info.totalswap - info.freeswap, |
72 | info.freeswap | 89 | info.freeswap |
73 | ); | 90 | ); |
74 | printf("%6s%13lu%13lu%13lu\n", "Total:", | ||
75 | info.totalram + info.totalswap, | ||
76 | (info.totalram - info.freeram) + (info.totalswap - info.freeswap), | ||
77 | info.freeram + info.freeswap | ||
78 | ); | ||
79 | #endif | 91 | #endif |
80 | return EXIT_SUCCESS; | 92 | return EXIT_SUCCESS; |
81 | } | 93 | } |