diff options
author | Elliott Hughes <enh@google.com> | 2015-10-31 13:42:34 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-11-02 01:40:46 -0600 |
commit | 9d57762c921e77a7237981916d3109bbd3607891 (patch) | |
tree | 6d53451a19feb4958cf977db45e1eb3ce49fa6be /toys/posix | |
parent | 3c0f6a19a271a7b85d62fc85d0ac1c6f661849f2 (diff) | |
download | toybox-9d57762c921e77a7237981916d3109bbd3607891.tar.gz |
Fix the ps -o CMD vs COMM distinction.
"comm" is the command name without arguments, and "cmd" the command
line including arguments. Confusingly, "command" is a synonym for
the *latter*, not the former.
This implementation of "comm" matches the GNU ps behavior where the
names are truncated, but Android historically used the full name
from /proc/pid/cmdline instead, so this patch isn't sufficient to
let us match the Android behavior.
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/ps.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c index d0975de0..4f393824 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -70,7 +70,8 @@ config PS Available -o FIELDs: ADDR Instruction pointer - CMD Command line + CMD Command line (including args) + COMM Command name (no args) ETIME Elapsed time since process start F Process flags (PF_*) from linux source file include/sched.h (in octal rather than hex because posix) @@ -349,11 +350,11 @@ static int do_ps(struct dirtree *new) unit /= j ? 60 : 24; } - // COMMAND CMD + // COMM - command line including arguments // Command line limited to 2k displayable. We could dynamically malloc, but // it'd almost never get used, querying length of a proc file is awkward, // fixed buffer is nommu friendly... Wait for somebody to complain. :) - } else if (i==14 || i==15) { + } else if (i==14) { int fd; len = 0; @@ -370,6 +371,11 @@ static int do_ps(struct dirtree *new) } if (len<1) sprintf(out, "[%.*s]", nlen, name); + + // CMD - command name (without arguments) + } else if (i==15) { + sprintf(out, "%.*s", nlen, name); + // %CPU } else if (i==18) { ll = (get_uptime()*sysconf(_SC_CLK_TCK)-slot[19]); |