1 /* vi: set sw=4 ts=4: */
3 * Mini free implementation for busybox
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2, see file LICENSE in this source tree.
10 /* getopt not needed */
14 int free_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15 int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
21 if (argv[1] && argv[1][0] == '-')
27 /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
29 if (info.mem_unit != 0) {
30 mem_unit = info.mem_unit;
33 /* Convert values to kbytes */
38 info.totalswap >>= 10;
41 info.sharedram >>= 10;
42 info.bufferram >>= 10;
45 /* TODO: Make all this stuff not overflow when mem >= 4 Tb */
46 info.totalram *= mem_unit;
47 info.freeram *= mem_unit;
49 info.totalswap *= mem_unit;
50 info.freeswap *= mem_unit;
52 info.sharedram *= mem_unit;
53 info.bufferram *= mem_unit;
56 printf(" %13s%13s%13s%13s%13s\n",
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.
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)
72 info.totalram - info.freeram,
74 info.sharedram, info.bufferram
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: ");
81 info.totalram - info.freeram - info.bufferram,
82 info.freeram + info.bufferram
88 info.totalswap - info.freeswap,