killall, pidof: use argv0 for process matching too

top: show cmdline, not comm field
(fixes problems with re-execed applets showing as processes with name "exe",
and not being found by pidof/killall by applet name)

function                                             old     new   delta
find_pid_by_name                                      98     156     +58
procps_scan                                          692     732     +40
top_main                                            2724    2762     +38
find_pair                                            164     180     +16
collect_int                                          114     123      +9
cmp_main                                             547     555      +8
collect_fork                                         112     119      +7
collect_ctx                                          112     119      +7
read_package_field                                   253     257      +4
passwd_main                                         1983    1985      +2
process_stdin                                        435     433      -2
xstrtoul_range_sfx                                   229     226      -3
get_next_block                                      1852    1849      -3
arith                                               2042    2033      -9
sv_main                                             1236    1226     -10
singlemount                                         4690    4672     -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 10/6 up/down: 189/-45)          Total: 144 bytes
   text    data     bss     dec     hex filename
 734789    3028   14400  752217   b7a59 busybox_old
 734933    3028   14400  752361   b7ae9 busybox_unstripped
This commit is contained in:
Denis Vlasenko
2007-06-30 08:03:26 +00:00
parent 42ee26d00c
commit f7d07b1723
4 changed files with 60 additions and 27 deletions

View File

@@ -40,7 +40,8 @@ typedef struct top_status_t {
unsigned pid, ppid;
unsigned uid;
char state[4];
char comm[COMM_LEN];
/* TODO: read /proc/$PID/cmdline only for processes which are displayed */
char cmd[64];
} top_status_t;
typedef struct jiffy_counts_t{
@@ -444,7 +445,7 @@ static void display_status(int count, int scr_width)
#endif
);
if (col > 0)
printf("%.*s", col, s->comm);
printf("%.*s", col, s->cmd);
/* printf(" %d/%d %lld/%lld", s->pcpu, total_pcpu,
jif.busy - prev_jif.busy, jif.total - prev_jif.total); */
s++;
@@ -559,6 +560,7 @@ int top_main(int argc, char **argv)
| PSSCAN_UTIME
| PSSCAN_STATE
| PSSCAN_COMM
| PSSCAN_CMD
| PSSCAN_SID
| PSSCAN_UIDGID
))) {
@@ -572,7 +574,10 @@ int top_main(int argc, char **argv)
#endif
top[n].uid = p->uid;
strcpy(top[n].state, p->state);
strcpy(top[n].comm, p->comm);
if (p->cmd)
safe_strncpy(top[n].cmd, p->cmd, sizeof(top[n].cmd));
else /* mimic ps */
sprintf(top[n].cmd, "[%s]", p->comm);
}
if (ntop == 0) {
bb_error_msg_and_die("no process info in /proc");
@@ -585,6 +590,7 @@ int top_main(int argc, char **argv)
continue;
}
do_stats();
/* TODO: we don't need to sort all 10000 processes, we need to find top 24! */
qsort(top, ntop, sizeof(top_status_t), (void*)mult_lvl_cmp);
#else
qsort(top, ntop, sizeof(top_status_t), (void*)sort_function);