1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#define FOR_free
21#include "toys.h"
22
23GLOBALS(
24 unsigned bits;
25 unsigned long long units;
26 char *buf;
27)
28
29static char *convert(unsigned long d)
30{
31 long long ll = d*TT.units;
32 char *s = TT.buf;
33
34 if (FLAG(h)) human_readable(s, ll, 0);
35 else sprintf(s, "%llu",ll>>TT.bits);
36 TT.buf += strlen(TT.buf)+1;
37
38 return s;
39}
40
41void free_main(void)
42{
43 struct sysinfo in;
44
45 sysinfo(&in);
46 TT.units = in.mem_unit ? in.mem_unit : 1;
47 while ((toys.optflags&(FLAG_h-1)) && !(toys.optflags&(1<<TT.bits))) TT.bits++;
48 TT.bits *= 10;
49 TT.buf = toybuf;
50
51 xprintf("\t\ttotal used free shared buffers\n"
52 "Mem:%17s%12s%12s%12s%12s\n-/+ buffers/cache:%15s%12s\n"
53 "Swap:%16s%12s%12s\n", convert(in.totalram),
54 convert(in.totalram-in.freeram), convert(in.freeram), convert(in.sharedram),
55 convert(in.bufferram), convert(in.totalram - in.freeram - in.bufferram),
56 convert(in.freeram + in.bufferram), convert(in.totalswap),
57 convert(in.totalswap - in.freeswap), convert(in.freeswap));
58}
59