diff options
author | Rob Landley <rob@landley.net> | 2019-05-16 19:07:57 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-05-16 19:07:57 -0500 |
commit | ada1b3ab1edab71a185fba6c2ee98d1985933be5 (patch) | |
tree | f93030531b824be217cd44df9e8cf8778663390d /toys | |
parent | 7503a32bccae5949078dc7b3b7d15aaede25c4dc (diff) | |
download | toybox-ada1b3ab1edab71a185fba6c2ee98d1985933be5.tar.gz |
Have ps.c human_readable fields use all the available space.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/ps.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 826fadc4..0c8e8e81 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -588,10 +588,18 @@ static char *string_field(struct procpid *tb, struct ofields *field) // Human readable } else if (which <= PS_DIO) { - ll = slot[typos[which].slot]; + int i = abs(field->len); + + if (i<4) i = 4; + s = out; + if ((ll = slot[typos[which].slot])<0) { + ll = -ll; + *s++ = '-'; + if (i>4) i--; + } if (which <= PS_SHR) ll *= sysconf(_SC_PAGESIZE); if (TT.forcek) sprintf(out, "%lldk", ll/1024); - else human_readable(out, ll, 0); + else human_readable_long(s, ll, i-1, 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 @@ -781,8 +789,8 @@ static int get_ps(struct dirtree *new) slot[SLOT_ruid] = s ? atol(s) : new->st.st_uid; s = strafter(buf, "\nGid:"); slot[SLOT_rgid] = s ? atol(s) : new->st.st_gid; - if ((s = strafter(buf, "\nVmLck:"))) slot[SLOT_vmlck] = atoll(s); - if ((s = strafter(buf, "\nVmSwap:"))) slot[SLOT_swap] = atoll(s); + if ((s = strafter(buf, "\nVmLck:"))) slot[SLOT_vmlck] = atoll(s)*1024; + if ((s = strafter(buf, "\nVmSwap:"))) slot[SLOT_swap] = atoll(s)*1024; } // Do we need to read "io"? |