aboutsummaryrefslogtreecommitdiff
path: root/procps/ps.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-19 22:29:42 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-19 22:29:42 +0200
commitb410d4ada73e9ebb30b2b50266a13c30479f5f21 (patch)
tree0d842b9c0885d1cf06fa6aa67a720b31b89cca55 /procps/ps.c
parentf00cfdfae53d8ef623238ecb1001969b5f649cbd (diff)
downloadbusybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.tar.gz
busybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.tar.bz2
busybox-w32-b410d4ada73e9ebb30b2b50266a13c30479f5f21.zip
ps,top: add an option to show threads. +260 bytes of code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps/ps.c')
-rw-r--r--procps/ps.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/procps/ps.c b/procps/ps.c
index 6523f0f38..b35b49c04 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -17,7 +17,6 @@ enum { MAX_WIDTH = 2*1024 };
17#if ENABLE_DESKTOP 17#if ENABLE_DESKTOP
18 18
19#include <sys/times.h> /* for times() */ 19#include <sys/times.h> /* for times() */
20//#include <sys/sysinfo.h> /* for sysinfo() */
21#ifndef AT_CLKTCK 20#ifndef AT_CLKTCK
22#define AT_CLKTCK 17 21#define AT_CLKTCK 17
23#endif 22#endif
@@ -61,6 +60,7 @@ struct globals {
61#define kernel_HZ (G.kernel_HZ ) 60#define kernel_HZ (G.kernel_HZ )
62#define seconds_since_boot (G.seconds_since_boot) 61#define seconds_since_boot (G.seconds_since_boot)
63#define default_o (G.default_o ) 62#define default_o (G.default_o )
63#define INIT_G() do { } while (0)
64 64
65#if ENABLE_FEATURE_PS_TIME 65#if ENABLE_FEATURE_PS_TIME
66/* for ELF executables, notes are pushed before environment and args */ 66/* for ELF executables, notes are pushed before environment and args */
@@ -452,21 +452,34 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
452{ 452{
453 procps_status_t *p; 453 procps_status_t *p;
454 llist_t* opt_o = NULL; 454 llist_t* opt_o = NULL;
455 IF_SELINUX(int opt;) 455 int opt;
456 enum {
457 OPT_Z = (1 << 0),
458 OPT_o = (1 << 1),
459 OPT_a = (1 << 2),
460 OPT_A = (1 << 3),
461 OPT_d = (1 << 4),
462 OPT_e = (1 << 5),
463 OPT_f = (1 << 6),
464 OPT_l = (1 << 7),
465 OPT_T = (1 << 8) * ENABLE_FEATURE_SHOW_THREADS,
466 };
467
468 INIT_G();
456 469
457 // POSIX: 470 // POSIX:
458 // -a Write information for all processes associated with terminals 471 // -a Write information for all processes associated with terminals
459 // Implementations may omit session leaders from this list 472 // Implementations may omit session leaders from this list
460 // -A Write information for all processes 473 // -A Write information for all processes
461 // -d Write information for all processes, except session leaders 474 // -d Write information for all processes, except session leaders
462 // -e Write information for all processes (equivalent to -A.) 475 // -e Write information for all processes (equivalent to -A)
463 // -f Generate a full listing 476 // -f Generate a full listing
464 // -l Generate a long listing 477 // -l Generate a long listing
465 // -o col1,col2,col3=header 478 // -o col1,col2,col3=header
466 // Select which columns to display 479 // Select which columns to display
467 /* We allow (and ignore) most of the above. FIXME */ 480 /* We allow (and ignore) most of the above. FIXME */
468 opt_complementary = "o::"; 481 opt_complementary = "o::";
469 IF_SELINUX(opt =) getopt32(argv, "Zo:aAdefl", &opt_o); 482 opt = getopt32(argv, "Zo:aAdefl" IF_FEATURE_SHOW_THREADS("T"), &opt_o);
470 if (opt_o) { 483 if (opt_o) {
471 do { 484 do {
472 parse_o(llist_pop(&opt_o)); 485 parse_o(llist_pop(&opt_o));
@@ -474,7 +487,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
474 } else { 487 } else {
475 /* Below: parse_o() needs char*, NOT const char*... */ 488 /* Below: parse_o() needs char*, NOT const char*... */
476#if ENABLE_SELINUX 489#if ENABLE_SELINUX
477 if (!(opt & 1) || !is_selinux_enabled()) { 490 if (!(opt & OPT_Z) || !is_selinux_enabled()) {
478 /* no -Z or no SELinux: do not show LABEL */ 491 /* no -Z or no SELinux: do not show LABEL */
479 strcpy(default_o, DEFAULT_O_STR + sizeof(SELINUX_O_PREFIX)-1); 492 strcpy(default_o, DEFAULT_O_STR + sizeof(SELINUX_O_PREFIX)-1);
480 } else 493 } else
@@ -485,6 +498,10 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
485 parse_o(default_o); 498 parse_o(default_o);
486 } 499 }
487 post_process(); 500 post_process();
501#if ENABLE_FEATURE_SHOW_THREADS
502 if (opt & OPT_T)
503 need_flags |= PSSCAN_TASKS;
504#endif
488 505
489 /* Was INT_MAX, but some libc's go belly up with printf("%.*s") 506 /* Was INT_MAX, but some libc's go belly up with printf("%.*s")
490 * and such large widths */ 507 * and such large widths */
@@ -497,7 +514,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
497 format_header(); 514 format_header();
498 515
499 p = NULL; 516 p = NULL;
500 while ((p = procps_scan(p, need_flags))) { 517 while ((p = procps_scan(p, need_flags)) != NULL) {
501 format_process(p); 518 format_process(p);
502 } 519 }
503 520
@@ -558,7 +575,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
558 | PSSCAN_VSZ 575 | PSSCAN_VSZ
559 | PSSCAN_COMM 576 | PSSCAN_COMM
560 | use_selinux 577 | use_selinux
561 ))) { 578 )) != NULL) {
562#if ENABLE_SELINUX 579#if ENABLE_SELINUX
563 if (use_selinux) { 580 if (use_selinux) {
564 len = printf("%5u %-32.32s %s ", 581 len = printf("%5u %-32.32s %s ",