aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorGravatar Denys Vlasenko <vda.linux@googlemail.com>2009-07-03 22:16:17 +0200
committerGravatar Denys Vlasenko <vda.linux@googlemail.com>2009-07-03 22:16:17 +0200
commitfca70a8cce579ce8cc8caf246c22f0c6e6c6e139 (patch)
tree2c17970b64b12c34624a18cf42b2c39a2cb5329d /procps
parentc5d07fba29a477569a96777c9cab73e53b1ddd5c (diff)
downloadbusybox-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.gz
busybox-fca70a8cce579ce8cc8caf246c22f0c6e6c6e139.tar.bz2
ps: conditionally support additional -o FIELDs
function old new delta procps_scan 1409 1642 +233 out_spec 220 300 +80 func_ruser - 36 +36 func_rgroup - 36 +36 func_group 13 49 +36 func_nice - 29 +29 buffer_fill_and_print 179 196 +17 send_tree 355 360 +5 mkfs_vfat_main 1604 1609 +5 display_speed 85 90 +5 scriptreplay_main 194 197 +3 find_out_spec 55 58 +3 changepath 192 195 +3 sha1_process_block64 497 484 -13 ------------------------------------------------------------------------------ (add/remove: 3/0 grow/shrink: 10/1 up/down: 491/-13) Total: 478 bytes Signed-off-by: David Krakov <krakov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r--procps/Config.in13
-rw-r--r--procps/ps.c41
-rw-r--r--procps/top.c2
3 files changed, 44 insertions, 12 deletions
diff --git a/procps/Config.in b/procps/Config.in
index 702442a52..9146ff6bf 100644
--- a/procps/Config.in
+++ b/procps/Config.in
@@ -91,13 +91,13 @@ config PS
ps gives a snapshot of the current processes.
config FEATURE_PS_WIDE
- bool "Enable argument for wide output (-w)"
+ bool "Enable wide output option (-w)"
default n
depends on PS
help
Support argument 'w' for wide output.
- If given once, 132 chars are printed and given more than
- one, the length is unlimited.
+ If given once, 132 chars are printed, and if given more
+ than once, the length is unlimited.
config FEATURE_PS_TIME
bool "Enable time and elapsed time output"
@@ -106,6 +106,13 @@ config FEATURE_PS_TIME
help
Support -o time and -o etime output specifiers.
+config FEATURE_PS_ADDITIONAL_COLUMNS
+ bool "Enable additional ps columns"
+ default n
+ depends on PS && DESKTOP
+ help
+ Support -o rgroup, -o ruser, -o nice output specifiers.
+
config FEATURE_PS_UNUSUAL_SYSTEMS
bool "Support Linux prior to 2.4.0 and non-ELF systems"
default n
diff --git a/procps/ps.c b/procps/ps.c
index b9a4aef15..4a6b60bdc 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -32,7 +32,7 @@ enum { MAX_WIDTH = 2*1024 };
typedef struct {
uint16_t width;
- char name[6];
+ char name6[6];
const char *header;
void (*f)(char *buf, int size, const procps_status_t *ps);
int ps_flags;
@@ -174,6 +174,11 @@ static void func_user(char *buf, int size, const procps_status_t *ps)
#endif
}
+static void func_group(char *buf, int size, const procps_status_t *ps)
+{
+ safe_strncpy(buf, get_cached_groupname(ps->gid), size+1);
+}
+
static void func_comm(char *buf, int size, const procps_status_t *ps)
{
safe_strncpy(buf, ps->comm, size+1);
@@ -227,6 +232,26 @@ static void func_tty(char *buf, int size, const procps_status_t *ps)
snprintf(buf, size+1, "%u,%u", ps->tty_major, ps->tty_minor);
}
+
+#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
+
+static void func_rgroup(char *buf, int size, const procps_status_t *ps)
+{
+ safe_strncpy(buf, get_cached_groupname(ps->rgid), size+1);
+}
+
+static void func_ruser(char *buf, int size, const procps_status_t *ps)
+{
+ safe_strncpy(buf, get_cached_username(ps->ruid), size+1);
+}
+
+static void func_nice(char *buf, int size, const procps_status_t *ps)
+{
+ sprintf(buf, "%*d", size, ps->niceness);
+}
+
+#endif /* FEATURE_PS_ADDITIONAL_COLUMNS */
+
#if ENABLE_FEATURE_PS_TIME
static void func_etime(char *buf, int size, const procps_status_t *ps)
{
@@ -276,6 +301,7 @@ static void func_pcpu(char *buf, int size, const procps_status_t *ps)
static const ps_out_t out_spec[] = {
// Mandated by POSIX:
{ 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID },
+ { 8 , "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID },
{ 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM },
{ 256 , "args" ,"COMMAND",func_args ,PSSCAN_COMM },
{ 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID },
@@ -284,11 +310,12 @@ static const ps_out_t out_spec[] = {
#if ENABLE_FEATURE_PS_TIME
{ sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_START_TIME },
#endif
-// { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID },
-// { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ },
-// { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ },
-// { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID },
-// { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID },
+#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
+ { 5 , "nice" ,"NI" ,func_nice ,PSSCAN_NICE },
+ { 8 , "rgroup","RGROUP" ,func_rgroup,PSSCAN_RUIDGID },
+ { 8 , "ruser" ,"RUSER" ,func_ruser ,PSSCAN_RUIDGID },
+// { 5 , "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ },
+#endif
#if ENABLE_FEATURE_PS_TIME
{ 6 , "time" ,"TIME" ,func_time ,PSSCAN_STIME | PSSCAN_UTIME },
#endif
@@ -311,7 +338,7 @@ static const ps_out_t* find_out_spec(const char *name)
{
unsigned i;
for (i = 0; i < ARRAY_SIZE(out_spec); i++) {
- if (!strcmp(name, out_spec[i].name))
+ if (!strncmp(name, out_spec[i].name6, 6))
return &out_spec[i];
}
bb_error_msg_and_die("bad -o argument '%s'", name);
diff --git a/procps/top.c b/procps/top.c
index 8738156e1..62b9c1e1b 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -871,9 +871,7 @@ enum {
| PSSCAN_UTIME
| PSSCAN_STATE
| PSSCAN_COMM
-#if ENABLE_FEATURE_TOP_SMP_PROCESS
| PSSCAN_CPU
-#endif
| PSSCAN_UIDGID,
TOPMEM_MASK = 0
| PSSCAN_PID