diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-19 14:46:14 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-04-19 14:46:14 +0000 |
commit | cff0c40a676337eb85bc57589bfe3436a9d21613 (patch) | |
tree | 4685bf59c11f898fad44f6e38cde3d16e43c723d /procps/ps.c | |
parent | f3ed3d787ee3079c43760fe1ea1475cffdc1d8bb (diff) | |
download | busybox-w32-cff0c40a676337eb85bc57589bfe3436a9d21613.tar.gz busybox-w32-cff0c40a676337eb85bc57589bfe3436a9d21613.tar.bz2 busybox-w32-cff0c40a676337eb85bc57589bfe3436a9d21613.zip |
ps: add -o tty and -o rss support
1373 14 24 1411 583 busybox.t1/procps/ps.o
1462 14 24 1500 5dc busybox.t2/procps/ps.o
git-svn-id: svn://busybox.net/trunk/busybox@18496 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'procps/ps.c')
-rw-r--r-- | procps/ps.c | 79 |
1 files changed, 45 insertions, 34 deletions
diff --git a/procps/ps.c b/procps/ps.c index f8f5c1aa9..0c9b71e09 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -29,83 +29,90 @@ static void func_args(char *buf, int size, const procps_status_t *ps) | |||
29 | if (ps->cmd) | 29 | if (ps->cmd) |
30 | safe_strncpy(buf, ps->cmd, size+1); | 30 | safe_strncpy(buf, ps->cmd, size+1); |
31 | else if (size >= 2) | 31 | else if (size >= 2) |
32 | snprintf(buf, size+1, "[%.*s]", size-2, ps->comm); | 32 | sprintf(buf, "[%.*s]", size-2, ps->comm); |
33 | } | 33 | } |
34 | 34 | ||
35 | static void func_pid(char *buf, int size, const procps_status_t *ps) | 35 | static void func_pid(char *buf, int size, const procps_status_t *ps) |
36 | { | 36 | { |
37 | snprintf(buf, size+1, "%*u", size, ps->pid); | 37 | sprintf(buf, "%*u", size, ps->pid); |
38 | } | 38 | } |
39 | 39 | ||
40 | static void func_ppid(char *buf, int size, const procps_status_t *ps) | 40 | static void func_ppid(char *buf, int size, const procps_status_t *ps) |
41 | { | 41 | { |
42 | snprintf(buf, size+1, "%*u", size, ps->ppid); | 42 | sprintf(buf, "%*u", size, ps->ppid); |
43 | } | 43 | } |
44 | 44 | ||
45 | static void func_pgid(char *buf, int size, const procps_status_t *ps) | 45 | static void func_pgid(char *buf, int size, const procps_status_t *ps) |
46 | { | 46 | { |
47 | snprintf(buf, size+1, "%*u", size, ps->pgid); | 47 | sprintf(buf, "%*u", size, ps->pgid); |
48 | } | 48 | } |
49 | 49 | ||
50 | static void func_vsz(char *buf, int size, const procps_status_t *ps) | 50 | static void func_vsz(char *buf, int size, const procps_status_t *ps) |
51 | { | 51 | { |
52 | char buf5[5]; | 52 | char buf5[5]; |
53 | smart_ulltoa5( ((unsigned long long)ps->vsz) << 10, buf5); | 53 | smart_ulltoa5( ((unsigned long long)ps->vsz) << 10, buf5); |
54 | snprintf(buf, size+1, "%.*s", size, buf5); | 54 | sprintf(buf, "%.*s", size, buf5); |
55 | } | 55 | } |
56 | 56 | ||
57 | static void func_rss(char *buf, int size, const procps_status_t *ps) | ||
58 | { | ||
59 | char buf5[5]; | ||
60 | smart_ulltoa5( ((unsigned long long)ps->rss) << 10, buf5); | ||
61 | sprintf(buf, "%.*s", size, buf5); | ||
62 | } | ||
63 | |||
64 | static void func_tty(char *buf, int size, const procps_status_t *ps) | ||
65 | { | ||
66 | safe_strncpy(buf, ps->tty_str, size+1); | ||
67 | } | ||
57 | /* | 68 | /* |
58 | void func_nice(char *buf, int size, const procps_status_t *ps) | 69 | static void func_nice(char *buf, int size, const procps_status_t *ps) |
59 | { | 70 | { |
60 | ps->??? | 71 | ps->??? |
61 | } | 72 | } |
62 | 73 | ||
63 | void func_etime(char *buf, int size, const procps_status_t *ps) | 74 | static void func_etime(char *buf, int size, const procps_status_t *ps) |
64 | { | 75 | { |
65 | elapled time [[dd-]hh:]mm:ss | 76 | elapled time [[dd-]hh:]mm:ss |
66 | } | 77 | } |
67 | 78 | ||
68 | void func_time(char *buf, int size, const procps_status_t *ps) | 79 | static void func_time(char *buf, int size, const procps_status_t *ps) |
69 | { | 80 | { |
70 | cumulative time [[dd-]hh:]mm:ss | 81 | cumulative time [[dd-]hh:]mm:ss |
71 | } | 82 | } |
72 | 83 | ||
73 | void func_pcpu(char *buf, int size, const procps_status_t *ps) | 84 | static void func_pcpu(char *buf, int size, const procps_status_t *ps) |
74 | { | ||
75 | } | ||
76 | |||
77 | void func_tty(char *buf, int size, const procps_status_t *ps) | ||
78 | { | 85 | { |
79 | } | 86 | } |
80 | */ | 87 | */ |
81 | 88 | ||
82 | typedef struct { | 89 | typedef struct { |
83 | char name[8]; | 90 | uint16_t width; |
91 | char name[6]; | ||
84 | const char *header; | 92 | const char *header; |
85 | void (*f)(char *buf, int size, const procps_status_t *ps); | 93 | void (*f)(char *buf, int size, const procps_status_t *ps); |
86 | int ps_flags; | 94 | int ps_flags; |
87 | int width; | ||
88 | } ps_out_t; | 95 | } ps_out_t; |
89 | 96 | ||
90 | static const ps_out_t out_spec[] = { | 97 | static const ps_out_t out_spec[] = { |
91 | // Mandated by POSIX: | 98 | // Mandated by POSIX: |
92 | { "user" ,"USER" ,func_user ,PSSCAN_UIDGID,8 }, | 99 | { 8 , "user" ,"USER" ,func_user ,PSSCAN_UIDGID }, |
93 | { "comm" ,"COMMAND",func_comm ,PSSCAN_COMM ,16 }, | 100 | { 16 , "comm" ,"COMMAND",func_comm ,PSSCAN_COMM }, |
94 | { "args" ,"COMMAND",func_args ,PSSCAN_CMD|PSSCAN_COMM,256 }, | 101 | { 256 , "args" ,"COMMAND",func_args ,PSSCAN_CMD|PSSCAN_COMM }, |
95 | { "pid" ,"PID" ,func_pid ,PSSCAN_PID ,5 }, | 102 | { 5 , "pid" ,"PID" ,func_pid ,PSSCAN_PID }, |
96 | { "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID ,5 }, | 103 | { 5 , "ppid" ,"PPID" ,func_ppid ,PSSCAN_PPID }, |
97 | { "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID ,5 }, | 104 | { 5 , "pgid" ,"PGID" ,func_pgid ,PSSCAN_PGID }, |
98 | // { "etime" ,"ELAPSED",func_etime ,PSSCAN_ ,sizeof("ELAPSED")-1 }, | 105 | // { sizeof("ELAPSED")-1, "etime" ,"ELAPSED",func_etime ,PSSCAN_ }, |
99 | // { "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID,sizeof("GROUP" )-1 }, | 106 | // { sizeof("GROUP" )-1, "group" ,"GROUP" ,func_group ,PSSCAN_UIDGID }, |
100 | // { "nice" ,"NI" ,func_nice ,PSSCAN_ ,sizeof("NI" )-1 }, | 107 | // { sizeof("NI" )-1, "nice" ,"NI" ,func_nice ,PSSCAN_ }, |
101 | // { "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ ,sizeof("%CPU" )-1 }, | 108 | // { sizeof("%CPU" )-1, "pcpu" ,"%CPU" ,func_pcpu ,PSSCAN_ }, |
102 | // { "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID,sizeof("RGROUP" )-1 }, | 109 | // { sizeof("RGROUP" )-1, "rgroup","RGROUP" ,func_rgroup,PSSCAN_UIDGID }, |
103 | // { "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID,sizeof("RUSER" )-1 }, | 110 | // { sizeof("RUSER" )-1, "ruser" ,"RUSER" ,func_ruser ,PSSCAN_UIDGID }, |
104 | // { "time" ,"TIME" ,func_time ,PSSCAN_ ,sizeof("TIME" )-1 }, | 111 | // { sizeof("TIME" )-1, "time" ,"TIME" ,func_time ,PSSCAN_ }, |
105 | // { "tty" ,"TT" ,func_tty ,PSSCAN_ ,sizeof("TT" )-1 }, | 112 | { sizeof("TT" )-1, "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, |
106 | { "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ ,4 }, | 113 | { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, |
107 | // Not mandated by POSIX: | 114 | // Not mandated by POSIX, but useful: |
108 | // { "rss" ,"RSS" ,func_rss ,PSSCAN_RSS ,4 }, | 115 | { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, |
109 | }; | 116 | }; |
110 | 117 | ||
111 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) | 118 | #define VEC_SIZE(v) ( sizeof(v) / sizeof((v)[0]) ) |
@@ -152,6 +159,8 @@ static void parse_o(char* opt) | |||
152 | } | 159 | } |
153 | break; | 160 | break; |
154 | } | 161 | } |
162 | // opt points to last spec in comma separated list. | ||
163 | // This one can have =HEADER part. | ||
155 | new = new_out_t(); | 164 | new = new_out_t(); |
156 | if (equal) | 165 | if (equal) |
157 | *equal = '\0'; | 166 | *equal = '\0'; |
@@ -190,9 +199,11 @@ static void format_header(void) | |||
190 | { | 199 | { |
191 | int i; | 200 | int i; |
192 | ps_out_t* op; | 201 | ps_out_t* op; |
193 | char *p = buffer; | 202 | char *p; |
203 | |||
194 | if (!print_header) | 204 | if (!print_header) |
195 | return; | 205 | return; |
206 | p = buffer; | ||
196 | i = 0; | 207 | i = 0; |
197 | if (out_cnt) { | 208 | if (out_cnt) { |
198 | while (1) { | 209 | while (1) { |
@@ -248,7 +259,7 @@ int ps_main(int argc, char **argv) | |||
248 | // -f Generate a full listing | 259 | // -f Generate a full listing |
249 | // -l Generate a long listing | 260 | // -l Generate a long listing |
250 | // -o col1,col2,col3=header | 261 | // -o col1,col2,col3=header |
251 | // Select which columns to distplay | 262 | // Select which columns to display |
252 | /* We allow (and ignore) most of the above. FIXME */ | 263 | /* We allow (and ignore) most of the above. FIXME */ |
253 | opt_complementary = "o::"; | 264 | opt_complementary = "o::"; |
254 | getopt32(argc, argv, "o:aAdefl", &opt_o); | 265 | getopt32(argc, argv, "o:aAdefl", &opt_o); |