From 976eaf88226776260c41b44cce98125ca0b638d6 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 7 Nov 2015 09:44:10 -0800 Subject: [PATCH] Add ps -o CMDLINE. This is equivalent to Android's historical "NAME" column, showing the first element of /proc/pid/cmdline. --- toys/posix/ps.c | 82 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index 6af02a08..0f73d820 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -69,42 +69,43 @@ config PS Available -o FIELDs: - ADDR Instruction pointer - 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) - GID Group id - GROUP Group name - LABEL Security label - MAJFL Major page faults - MINFL Minor page faults - NI Niceness of process (lower niceness is higher priority) - PCPU Percentage of CPU time used - PGID Process Group ID - PID Process ID - PPID Parent Process ID - PRI Priority - RGID Real (before sgid) group ID - RGROUP Real (before sgid) group name - RSS Resident Set Size (memory currently used) - RUID Real (before suid) user ID - RUSER Real (before suid) user name - S Process state: - R (running) S (sleeping) D (disk sleep) T (stopped) t (traced) - Z (zombie) X (dead) x (dead) K (wakekill) W (waking) - STAT Process state (S) plus: - < high priority N low priority L locked memory - s session leader + foreground l multithreaded - STIME Start time of process in hh:mm (size :19 shows yyyy-mm-dd hh:mm:ss) - SZ Memory Size (4k pages needed to completely swap out process) - TIME CPU time consumed - TTY Controlling terminal - UID User id - USER User name - VSZ Virtual memory size (1k units) - WCHAN Waiting in kernel for + ADDR Instruction pointer + CMD Command line (from /proc/pid/cmdline, including args) + CMDLINE Command line (from /proc/pid/cmdline, no args) + COMM Command name (from /proc/pid/stat, 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) + GID Group id + GROUP Group name + LABEL Security label + MAJFL Major page faults + MINFL Minor page faults + NI Niceness of process (lower niceness is higher priority) + PCPU Percentage of CPU time used + PGID Process Group ID + PID Process ID + PPID Parent Process ID + PRI Priority + RGID Real (before sgid) group ID + RGROUP Real (before sgid) group name + RSS Resident Set Size (memory currently used) + RUID Real (before suid) user ID + RUSER Real (before suid) user name + S Process state: + R (running) S (sleeping) D (disk sleep) T (stopped) t (traced) + Z (zombie) X (dead) x (dead) K (wakekill) W (waking) + STAT Process state (S) plus: + < high priority N low priority L locked memory + s session leader + foreground l multithreaded + STIME Start time of process in hh:mm (size :19 shows yyyy-mm-dd hh:mm:ss) + SZ Memory Size (4k pages needed to completely swap out process) + TIME CPU time consumed + TTY Controlling terminal + UID User id + USER User name + VSZ Virtual memory size (1k units) + WCHAN Waiting in kernel for */ #define FOR_ps @@ -354,7 +355,8 @@ static int do_ps(struct dirtree *new) // 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) { + // CMDLINE - command line from /proc/pid/cmdline without arguments + } else if (i==14 || i==32) { int fd; len = 0; @@ -365,7 +367,7 @@ static int do_ps(struct dirtree *new) if (0<(len = read(fd, out, 2047))) { if (!out[len-1]) len--; else out[len] = 0; - for (i = 0; i