diff options
author | Denys Vlasenko | 2011-02-02 00:59:35 +0100 |
---|---|---|
committer | Denys Vlasenko | 2011-02-02 00:59:35 +0100 |
commit | 099e528919e2219772265e99ab8a43d188c1b8db (patch) | |
tree | 0c8cece10d0aa44a014bc71e9f9ffcb5bfa8bb14 /procps | |
parent | c5830bdf6558edbc567d7c5dce1ff8059049e202 (diff) | |
download | busybox-099e528919e2219772265e99ab8a43d188c1b8db.zip busybox-099e528919e2219772265e99ab8a43d188c1b8db.tar.gz |
ps: implement -o stat
function old new delta
func_stat - 24 +24
out_spec 300 320 +20
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r-- | procps/ps.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/procps/ps.c b/procps/ps.c index 48b55a7..6945780 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -18,15 +18,34 @@ enum { MAX_WIDTH = 2*1024 }; #include <sys/times.h> /* for times() */ #ifndef AT_CLKTCK -#define AT_CLKTCK 17 +# define AT_CLKTCK 17 #endif - +/* TODO: + * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html + * specifies (for XSI-conformant systems) following default columns + * (l and f mark columns shown with -l and -f respectively): + * F l Flags (octal and additive) associated with the process (??) + * S l The state of the process + * UID f,l The user ID; the login name is printed with -f + * PID The process ID + * PPID f,l The parent process + * C f,l Processor utilization + * PRI l The priority of the process; higher numbers mean lower priority + * NI l Nice value + * ADDR l The address of the process + * SZ l The size in blocks of the core image of the process + * WCHAN l The event for which the process is waiting or sleeping + * STIME f Starting time of the process + * TTY The controlling terminal for the process + * TIME The cumulative execution time for the process + * CMD The command name; the full command line is shown with -f + */ #if ENABLE_SELINUX -#define SELINUX_O_PREFIX "label," -#define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") +# define SELINUX_O_PREFIX "label," +# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") #else -#define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") +# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") #endif typedef struct { @@ -68,7 +87,8 @@ static ptrdiff_t find_elf_note(ptrdiff_t findme) { ptrdiff_t *ep = (ptrdiff_t *) environ; - while (*ep++); + while (*ep++) + continue; while (*ep) { if (ep[0] == findme) { return ep[1]; @@ -184,6 +204,11 @@ static void func_comm(char *buf, int size, const procps_status_t *ps) safe_strncpy(buf, ps->comm, size+1); } +static void func_stat(char *buf, int size, const procps_status_t *ps) +{ + safe_strncpy(buf, ps->state, size+1); +} + static void func_args(char *buf, int size, const procps_status_t *ps) { read_cmdline(buf, size+1, ps->pid, ps->comm); @@ -300,7 +325,7 @@ static void func_pcpu(char *buf, int size, const procps_status_t *ps) */ static const ps_out_t out_spec[] = { -// Mandated by POSIX: +/* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html: */ { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, @@ -322,7 +347,8 @@ static const ps_out_t out_spec[] = { #endif { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, -// Not mandated by POSIX, but useful: +/* Not mandated, but useful: */ + { 4 , "stat" ,"STAT" ,func_stat ,PSSCAN_STAT }, { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, #if ENABLE_SELINUX { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, |