From 9d57762c921e77a7237981916d3109bbd3607891 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 31 Oct 2015 13:42:34 -0700 Subject: 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. --- toys/posix/ps.c | 12 +++++++++--- 1 file 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]); -- cgit v1.2.3