diff options
author | Elliott Hughes <enh@google.com> | 2019-02-16 22:48:44 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-17 14:03:19 -0600 |
commit | 5e99343e8951e6511a7b9b21c0223bff35b35542 (patch) | |
tree | 7e422a7203de5dd4ab6f95f2fdbc71c161dc2fbf | |
parent | 9197c0ae1d5206f74284018c78538a38375af3c1 (diff) | |
download | toybox-5e99343e8951e6511a7b9b21c0223bff35b35542.tar.gz |
top: make the task/thread count add up.
Linux has more states than we were giving it credit for, which led to
our numbers not adding up. Since the exact details seem to change
between versions, and since having code specific to each kernel version
is unattractive, go with the heuristic that there are relatively fewer
"stopped" states (and they change less frequently), so all unknowns are
"sleeping".
-rw-r--r-- | toys/posix/ps.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 279a947a..c0e7e9e9 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -385,8 +385,10 @@ struct typography { {"STIME", "Start time (ISO 8601)", 5, SLOT_starttime}, {"F", "Flags 1=FORKNOEXEC 4=SUPERPRIV", 1, XX|SLOT_flags}, {"S", "Process state:\n" - "\t R (running) S (sleeping) D (device I/O) T (stopped) t (traced)\n" - "\t Z (zombie) X (deader) x (dead) K (wakekill) W (waking)", + "\t R (running) S (sleeping) D (device I/O) T (stopped) t (trace stop)\n" + "\t X (dead) Z (zombie) P (parked) I (idle)\n" + "\t Also between Linux 2.6.33 and 3.13:\n" + "\t x (dead) K (wakekill) W (waking)\n", -1, XX}, {"STAT", "Process state (S) plus:\n" "\t < high priority N low priority L locked memory\n" @@ -1553,13 +1555,18 @@ static void top_common( int j; // Count running, sleeping, stopped, zombie processes. + // The kernel has more states (and different sets in different + // versions), so we need to map them. (R)unning and (Z)ombie are + // easy enough, and since "stopped" is rare (just T and t as of + // Linux 4.20), we assume everything else is "sleeping". field.which = PS_S; memset(run, 0, sizeof(run)); for (i = 0; i<mix.count; i++) - run[1+stridx("RSTZ", *string_field(mix.tb[i], &field))]++; + run[1+stridx("RTtZ", *string_field(mix.tb[i], &field))]++; sprintf(toybuf, - "%ss: %d total,%4ld running,%4ld sleeping,%4ld stopped,%4ld zombie", - FLAG(H)?"Thread":"Task", mix.count, run[1], run[2], run[3], run[4]); + "%ss: %d total, %3ld running, %3ld sleeping, %3ld stopped, " + "%3ld zombie", FLAG(H)?"Thread":"Task", mix.count, run[1], run[0], + run[2]+run[3], run[4]); lines = header_line(lines, 0); if (readfile("/proc/meminfo", toybuf, sizeof(toybuf))) { |