aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-09-04 01:04:43 -0500
committerRob Landley <rob@landley.net>2020-09-04 01:04:43 -0500
commitec5e6e12ee6d7047ab013f3a2826abdb52666ea0 (patch)
tree0a14a66b2dab3daa67da89d8bf6ce8032ccb5527 /toys/posix
parentcb064374c86259f74899162b28c4896e898401e3 (diff)
downloadtoybox-ec5e6e12ee6d7047ab013f3a2826abdb52666ea0.tar.gz
Add commas to top display, and adjust memory units to megabytes if >10G RAM.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/ps.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index cd8c73ea..8707ae5a 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -600,7 +600,7 @@ static char *string_field(struct procpid *tb, struct ofields *field)
}
if (which <= PS_SHR) ll *= sysconf(_SC_PAGESIZE);
if (TT.forcek) sprintf(out, "%lldk", ll/1024);
- else human_readable_long(s, ll, i-1, 0);
+ else human_readable_long(s, ll, i-1, 0, 0);
// Posix doesn't specify what flags should say. Man page says
// 1 for PF_FORKNOEXEC and 4 for PF_SUPERPRIV from linux/sched.h
@@ -1568,7 +1568,7 @@ static void top_common(
char hr[4][32];
long long ll, up = 0;
long run[6];
- int j;
+ int j, k;
// Count running, sleeping, stopped, zombie processes.
// The kernel has more states (and different sets in different
@@ -1590,19 +1590,19 @@ static void top_common(
j = i%3;
pos = strafter(toybuf+256, (char *[]){"MemTotal:","\nMemFree:",
"\nBuffers:","\nSwapTotal:","\nSwapFree:","\nCached:"}[i]);
- human_readable_long(hr[j+!!j], 1024*(run[i] = pos?atol(pos):0),
- 8, 0);
- if (j==1) human_readable_long(hr[1], 1024*(run[i-1]-run[i]), 8,0);
+ run[i] = pos ? atol(pos) : 0;
+ k = (*run>=10000000);
+ human_readable_long(hr[j+!!j], run[i]>>(10*k), 8, k+1, HR_COMMAS);
+ if (j==1) human_readable_long(hr[1], (run[i-1]-run[i])>>(10*k),
+ 8, k+1, HR_COMMAS);
else if (j==2) {
- sprintf(toybuf, (i<3)
- ? " Mem: %9s total, %9s used, %9s free, %9s buffers"
- : " Swap: %9s total, %9s used, %9s free, %9s cached",
- hr[0], hr[1], hr[2], hr[3]);
+ sprintf(toybuf, " %s: %9s total, %9s used, %9s free, %9s %s",
+ (i<3) ? " Mem" : "Swap", hr[0], hr[1], hr[2], hr[3],
+ (i<3) ? "buffers" : "cached");
lines = header_line(lines, 0);
}
}
}
-
pos = toybuf;
i = sysconf(_SC_NPROCESSORS_CONF);
pos += sprintf(pos, "%d%%cpu", i*100);