diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-02 00:59:35 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-02-02 00:59:35 +0100 |
commit | 099e528919e2219772265e99ab8a43d188c1b8db (patch) | |
tree | 0c8cece10d0aa44a014bc71e9f9ffcb5bfa8bb14 | |
parent | c5830bdf6558edbc567d7c5dce1ff8059049e202 (diff) | |
download | busybox-w32-099e528919e2219772265e99ab8a43d188c1b8db.tar.gz busybox-w32-099e528919e2219772265e99ab8a43d188c1b8db.tar.bz2 busybox-w32-099e528919e2219772265e99ab8a43d188c1b8db.zip |
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>
-rw-r--r-- | miscutils/timeout.c | 2 | ||||
-rw-r--r-- | procps/ps.c | 42 |
2 files changed, 35 insertions, 9 deletions
diff --git a/miscutils/timeout.c b/miscutils/timeout.c index 48b8d8fc0..841669416 100644 --- a/miscutils/timeout.c +++ b/miscutils/timeout.c | |||
@@ -83,7 +83,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv) | |||
83 | bb_daemonize_or_rexec(0, argv); | 83 | bb_daemonize_or_rexec(0, argv); |
84 | /* Here we are grandchild. Sleep, then kill grandparent */ | 84 | /* Here we are grandchild. Sleep, then kill grandparent */ |
85 | grandchild: | 85 | grandchild: |
86 | /* Just sleep(NUGE_NUM); kill(parent) may kill wrong process! */ | 86 | /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */ |
87 | while (1) { | 87 | while (1) { |
88 | sleep(1); | 88 | sleep(1); |
89 | if (--timeout <= 0) | 89 | if (--timeout <= 0) |
diff --git a/procps/ps.c b/procps/ps.c index 48b55a785..6945780ec 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -18,15 +18,34 @@ enum { MAX_WIDTH = 2*1024 }; | |||
18 | 18 | ||
19 | #include <sys/times.h> /* for times() */ | 19 | #include <sys/times.h> /* for times() */ |
20 | #ifndef AT_CLKTCK | 20 | #ifndef AT_CLKTCK |
21 | #define AT_CLKTCK 17 | 21 | # define AT_CLKTCK 17 |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | 24 | /* TODO: | |
25 | * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html | ||
26 | * specifies (for XSI-conformant systems) following default columns | ||
27 | * (l and f mark columns shown with -l and -f respectively): | ||
28 | * F l Flags (octal and additive) associated with the process (??) | ||
29 | * S l The state of the process | ||
30 | * UID f,l The user ID; the login name is printed with -f | ||
31 | * PID The process ID | ||
32 | * PPID f,l The parent process | ||
33 | * C f,l Processor utilization | ||
34 | * PRI l The priority of the process; higher numbers mean lower priority | ||
35 | * NI l Nice value | ||
36 | * ADDR l The address of the process | ||
37 | * SZ l The size in blocks of the core image of the process | ||
38 | * WCHAN l The event for which the process is waiting or sleeping | ||
39 | * STIME f Starting time of the process | ||
40 | * TTY The controlling terminal for the process | ||
41 | * TIME The cumulative execution time for the process | ||
42 | * CMD The command name; the full command line is shown with -f | ||
43 | */ | ||
25 | #if ENABLE_SELINUX | 44 | #if ENABLE_SELINUX |
26 | #define SELINUX_O_PREFIX "label," | 45 | # define SELINUX_O_PREFIX "label," |
27 | #define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") | 46 | # define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args") |
28 | #else | 47 | #else |
29 | #define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") | 48 | # define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args") |
30 | #endif | 49 | #endif |
31 | 50 | ||
32 | typedef struct { | 51 | typedef struct { |
@@ -68,7 +87,8 @@ static ptrdiff_t find_elf_note(ptrdiff_t findme) | |||
68 | { | 87 | { |
69 | ptrdiff_t *ep = (ptrdiff_t *) environ; | 88 | ptrdiff_t *ep = (ptrdiff_t *) environ; |
70 | 89 | ||
71 | while (*ep++); | 90 | while (*ep++) |
91 | continue; | ||
72 | while (*ep) { | 92 | while (*ep) { |
73 | if (ep[0] == findme) { | 93 | if (ep[0] == findme) { |
74 | return ep[1]; | 94 | return ep[1]; |
@@ -184,6 +204,11 @@ static void func_comm(char *buf, int size, const procps_status_t *ps) | |||
184 | safe_strncpy(buf, ps->comm, size+1); | 204 | safe_strncpy(buf, ps->comm, size+1); |
185 | } | 205 | } |
186 | 206 | ||
207 | static void func_stat(char *buf, int size, const procps_status_t *ps) | ||
208 | { | ||
209 | safe_strncpy(buf, ps->state, size+1); | ||
210 | } | ||
211 | |||
187 | static void func_args(char *buf, int size, const procps_status_t *ps) | 212 | static void func_args(char *buf, int size, const procps_status_t *ps) |
188 | { | 213 | { |
189 | read_cmdline(buf, size+1, ps->pid, ps->comm); | 214 | 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) | |||
300 | */ | 325 | */ |
301 | 326 | ||
302 | static const ps_out_t out_spec[] = { | 327 | static const ps_out_t out_spec[] = { |
303 | // Mandated by POSIX: | 328 | /* Mandated by http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html: */ |
304 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, | 329 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, |
305 | { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, | 330 | { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, |
306 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, | 331 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, |
@@ -322,7 +347,8 @@ static const ps_out_t out_spec[] = { | |||
322 | #endif | 347 | #endif |
323 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, | 348 | { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
324 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, | 349 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |
325 | // Not mandated by POSIX, but useful: | 350 | /* Not mandated, but useful: */ |
351 | { 4 , "stat" ,"STAT" ,func_stat ,PSSCAN_STAT }, | ||
326 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, | 352 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, |
327 | #if ENABLE_SELINUX | 353 | #if ENABLE_SELINUX |
328 | { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, | 354 | { 35 , "label" ,"LABEL" ,func_label ,PSSCAN_CONTEXT }, |