aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-22 15:41:00 +0000
committerRon Yorston <rmy@pobox.com>2012-03-22 15:41:00 +0000
commit1118c95535ea51961437089fc3dece5ab4ea7e1b (patch)
tree1515bd2376a6d6c5123791662307ce2ed90cdf36 /procps
parent0d8b2c4a929ea9d3ac37499319fe0d8e7941a0c2 (diff)
parent066f39956641300c1e5c6bfe6c11a115cea3e2cf (diff)
downloadbusybox-w32-1118c95535ea51961437089fc3dece5ab4ea7e1b.tar.gz
busybox-w32-1118c95535ea51961437089fc3dece5ab4ea7e1b.tar.bz2
busybox-w32-1118c95535ea51961437089fc3dece5ab4ea7e1b.zip
Merge commit '066f39956641300c1e5c6bfe6c11a115cea3e2cf' into merge
Conflicts: procps/ps.c
Diffstat (limited to 'procps')
-rw-r--r--procps/fuser.c1
-rw-r--r--procps/iostat.c238
-rw-r--r--procps/kill.c3
-rw-r--r--procps/mpstat.c1
-rw-r--r--procps/pgrep.c4
-rw-r--r--procps/pidof.c2
-rw-r--r--procps/pmap.c16
-rw-r--r--procps/ps.c30
-rw-r--r--procps/pstree.c1
-rw-r--r--procps/renice.c1
-rw-r--r--procps/sysctl.c1
-rw-r--r--procps/watch.c1
12 files changed, 141 insertions, 158 deletions
diff --git a/procps/fuser.c b/procps/fuser.c
index 8d63a7313..05b52abb1 100644
--- a/procps/fuser.c
+++ b/procps/fuser.c
@@ -11,7 +11,6 @@
11//usage: "[OPTIONS] FILE or PORT/PROTO" 11//usage: "[OPTIONS] FILE or PORT/PROTO"
12//usage:#define fuser_full_usage "\n\n" 12//usage:#define fuser_full_usage "\n\n"
13//usage: "Find processes which use FILEs or PORTs\n" 13//usage: "Find processes which use FILEs or PORTs\n"
14//usage: "\nOptions:"
15//usage: "\n -m Find processes which use same fs as FILEs" 14//usage: "\n -m Find processes which use same fs as FILEs"
16//usage: "\n -4,-6 Search only IPv4/IPv6 space" 15//usage: "\n -4,-6 Search only IPv4/IPv6 space"
17//usage: "\n -s Don't display PIDs" 16//usage: "\n -s Don't display PIDs"
diff --git a/procps/iostat.c b/procps/iostat.c
index cd233c72f..978d23430 100644
--- a/procps/iostat.c
+++ b/procps/iostat.c
@@ -7,23 +7,24 @@
7 * Licensed under GPLv2, see file LICENSE in this source tree. 7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */ 8 */
9 9
10//applet:IF_IOSTAT(APPLET(iostat, BB_DIR_BIN, BB_SUID_DROP))
11
12//kbuild:lib-$(CONFIG_IOSTAT) += iostat.o
13
14//config:config IOSTAT 10//config:config IOSTAT
15//config: bool "iostat" 11//config: bool "iostat"
16//config: default y 12//config: default y
17//config: help 13//config: help
18//config: Report CPU and I/O statistics 14//config: Report CPU and I/O statistics
19 15
16//applet:IF_IOSTAT(APPLET(iostat, BB_DIR_BIN, BB_SUID_DROP))
17
18//kbuild:lib-$(CONFIG_IOSTAT) += iostat.o
19
20#include "libbb.h" 20#include "libbb.h"
21#include <sys/utsname.h> /* Need struct utsname */ 21#include <sys/utsname.h> /* struct utsname */
22 22
23//#define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) 23//#define debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
24#define debug(fmt, ...) ((void)0) 24#define debug(fmt, ...) ((void)0)
25 25
26#define MAX_DEVICE_NAME 12 26#define MAX_DEVICE_NAME 12
27#define MAX_DEVICE_NAME_STR "12"
27 28
28#if 1 29#if 1
29typedef unsigned long long cputime_t; 30typedef unsigned long long cputime_t;
@@ -64,21 +65,27 @@ typedef struct {
64 cputime_t itv; 65 cputime_t itv;
65} stats_cpu_pair_t; 66} stats_cpu_pair_t;
66 67
67struct stats_dev { 68typedef struct {
68 char dname[MAX_DEVICE_NAME];
69 unsigned long long rd_sectors; 69 unsigned long long rd_sectors;
70 unsigned long long wr_sectors; 70 unsigned long long wr_sectors;
71 unsigned long rd_ops; 71 unsigned long rd_ops;
72 unsigned long wr_ops; 72 unsigned long wr_ops;
73}; 73} stats_dev_data_t;
74
75typedef struct stats_dev {
76 struct stats_dev *next;
77 char dname[MAX_DEVICE_NAME + 1];
78 stats_dev_data_t prev_data;
79 stats_dev_data_t curr_data;
80} stats_dev_t;
74 81
75/* Globals. Sort by size and access frequency. */ 82/* Globals. Sort by size and access frequency. */
76struct globals { 83struct globals {
77 smallint show_all; 84 smallint show_all;
78 unsigned total_cpus; /* Number of CPUs */ 85 unsigned total_cpus; /* Number of CPUs */
79 unsigned clk_tck; /* Number of clock ticks per second */ 86 unsigned clk_tck; /* Number of clock ticks per second */
80 llist_t *dev_list; /* List of devices entered on the command line */ 87 llist_t *dev_name_list; /* List of devices entered on the command line */
81 struct stats_dev *saved_stats_dev; 88 stats_dev_t *stats_dev_list;
82 struct tm tmtime; 89 struct tm tmtime;
83 struct { 90 struct {
84 const char *str; 91 const char *str;
@@ -114,7 +121,7 @@ static ALWAYS_INLINE int this_is_smp(void)
114 121
115static void print_header(void) 122static void print_header(void)
116{ 123{
117 char buf[16]; 124 char buf[32];
118 struct utsname uts; 125 struct utsname uts;
119 126
120 uname(&uts); /* never fails */ 127 uname(&uts); /* never fails */
@@ -136,7 +143,7 @@ static void get_localtime(struct tm *ptm)
136 143
137static void print_timestamp(void) 144static void print_timestamp(void)
138{ 145{
139 char buf[20]; 146 char buf[64];
140 /* %x: date representation for the current locale */ 147 /* %x: date representation for the current locale */
141 /* %X: time representation for the current locale */ 148 /* %X: time representation for the current locale */
142 strftime(buf, sizeof(buf), "%x %X", &G.tmtime); 149 strftime(buf, sizeof(buf), "%x %X", &G.tmtime);
@@ -162,18 +169,22 @@ static cputime_t get_smp_uptime(void)
162static void get_cpu_statistics(stats_cpu_t *sc) 169static void get_cpu_statistics(stats_cpu_t *sc)
163{ 170{
164 FILE *fp; 171 FILE *fp;
165 char buf[1024], *ibuf = buf + 4; 172 char buf[1024];
166 173
167 fp = xfopen_for_read("/proc/stat"); 174 fp = xfopen_for_read("/proc/stat");
168 175
169 memset(sc, 0, sizeof(*sc)); 176 memset(sc, 0, sizeof(*sc));
170 177
171 while (fgets(buf, sizeof(buf), fp)) { 178 while (fgets(buf, sizeof(buf), fp)) {
172 /* Does the line starts with "cpu "? */ 179 int i;
180 char *ibuf;
181
182 /* Does the line start with "cpu "? */
173 if (!starts_with_cpu(buf) || buf[3] != ' ') { 183 if (!starts_with_cpu(buf) || buf[3] != ' ') {
174 continue; 184 continue;
175 } 185 }
176 for (int i = STATS_CPU_USER; i <= STATS_CPU_GUEST; i++) { 186 ibuf = buf + 4;
187 for (i = STATS_CPU_USER; i <= STATS_CPU_GUEST; i++) {
177 ibuf = skip_whitespace(ibuf); 188 ibuf = skip_whitespace(ibuf);
178 sscanf(ibuf, "%"FMT_DATA"u", &sc->vector[i]); 189 sscanf(ibuf, "%"FMT_DATA"u", &sc->vector[i]);
179 if (i != STATS_CPU_GUEST) { 190 if (i != STATS_CPU_GUEST) {
@@ -233,7 +244,7 @@ static void print_stats_cpu_struct(stats_cpu_pair_t *stats)
233{ 244{
234 cputime_t *p = stats->prev->vector; 245 cputime_t *p = stats->prev->vector;
235 cputime_t *c = stats->curr->vector; 246 cputime_t *c = stats->curr->vector;
236 printf(" %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n", 247 printf(" %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n",
237 percent_value(p[STATS_CPU_USER] , c[STATS_CPU_USER] , stats->itv), 248 percent_value(p[STATS_CPU_USER] , c[STATS_CPU_USER] , stats->itv),
238 percent_value(p[STATS_CPU_NICE] , c[STATS_CPU_NICE] , stats->itv), 249 percent_value(p[STATS_CPU_NICE] , c[STATS_CPU_NICE] , stats->itv),
239 percent_value(p[STATS_CPU_SYSTEM] + p[STATS_CPU_SOFTIRQ] + p[STATS_CPU_IRQ], 250 percent_value(p[STATS_CPU_SYSTEM] + p[STATS_CPU_SOFTIRQ] + p[STATS_CPU_IRQ],
@@ -244,36 +255,40 @@ static void print_stats_cpu_struct(stats_cpu_pair_t *stats)
244 ); 255 );
245} 256}
246 257
247static void print_stats_dev_struct(const struct stats_dev *p, 258static void cpu_report(stats_cpu_pair_t *stats)
248 const struct stats_dev *c, cputime_t itv)
249{ 259{
260 /* Always print a header */
261 puts("avg-cpu: %user %nice %system %iowait %steal %idle");
262
263 /* Print current statistics */
264 print_stats_cpu_struct(stats);
265}
266
267static void print_stats_dev_struct(stats_dev_t *stats_dev, cputime_t itv)
268{
269 stats_dev_data_t *p = &stats_dev->prev_data;
270 stats_dev_data_t *c = &stats_dev->curr_data;
250 if (option_mask32 & OPT_z) 271 if (option_mask32 & OPT_z)
251 if (p->rd_ops == c->rd_ops && p->wr_ops == c->wr_ops) 272 if (p->rd_ops == c->rd_ops && p->wr_ops == c->wr_ops)
252 return; 273 return;
253 274
254 printf("%-13s %8.2f %12.2f %12.2f %10llu %10llu \n", c->dname, 275 printf("%-13s %8.2f %12.2f %12.2f %10llu %10llu\n",
255 percent_value(p->rd_ops + p->wr_ops , 276 stats_dev->dname,
256 /**/ c->rd_ops + c->wr_ops , itv), 277 percent_value(p->rd_ops + p->wr_ops, c->rd_ops + c->wr_ops, itv),
257 percent_value(p->rd_sectors, c->rd_sectors, itv) / G.unit.div, 278 percent_value(p->rd_sectors, c->rd_sectors, itv) / G.unit.div,
258 percent_value(p->wr_sectors, c->wr_sectors, itv) / G.unit.div, 279 percent_value(p->wr_sectors, c->wr_sectors, itv) / G.unit.div,
259 (c->rd_sectors - p->rd_sectors) / G.unit.div, 280 (c->rd_sectors - p->rd_sectors) / G.unit.div,
260 (c->wr_sectors - p->wr_sectors) / G.unit.div); 281 (c->wr_sectors - p->wr_sectors) / G.unit.div
261} 282 );
262
263static void cpu_report(stats_cpu_pair_t *stats)
264{
265 /* Always print a header */
266 puts("avg-cpu: %user %nice %system %iowait %steal %idle");
267
268 /* Print current statistics */
269 print_stats_cpu_struct(stats);
270} 283}
271 284
272static void print_devstat_header(void) 285static void print_devstat_header(void)
273{ 286{
274 printf("Device:%15s%6s%s/s%6s%s/s%6s%s%6s%s\n", "tps", 287 printf("Device:%15s%6s%s/s%6s%s/s%6s%s%6s%s\n",
288 "tps",
275 G.unit.str, "_read", G.unit.str, "_wrtn", 289 G.unit.str, "_read", G.unit.str, "_wrtn",
276 G.unit.str, "_read", G.unit.str, "_wrtn"); 290 G.unit.str, "_read", G.unit.str, "_wrtn"
291 );
277} 292}
278 293
279/* 294/*
@@ -285,61 +300,81 @@ static int is_partition(const char *dev)
285 return ((dev[0] - 's') | (dev[1] - 'd') | (dev[2] - 'a')) == 0 && isdigit(dev[3]); 300 return ((dev[0] - 's') | (dev[1] - 'd') | (dev[2] - 'a')) == 0 && isdigit(dev[3]);
286} 301}
287 302
303static stats_dev_t *stats_dev_find_or_new(const char *dev_name)
304{
305 stats_dev_t **curr = &G.stats_dev_list;
306
307 while (*curr != NULL) {
308 if (strcmp((*curr)->dname, dev_name) == 0)
309 return *curr;
310 curr = &(*curr)->next;
311 }
312
313 *curr = xzalloc(sizeof(stats_dev_t));
314 strncpy((*curr)->dname, dev_name, MAX_DEVICE_NAME);
315 return *curr;
316}
317
318static void stats_dev_free(stats_dev_t *stats_dev)
319{
320 if (stats_dev) {
321 stats_dev_free(stats_dev->next);
322 free(stats_dev);
323 }
324}
325
288static void do_disk_statistics(cputime_t itv) 326static void do_disk_statistics(cputime_t itv)
289{ 327{
328 char buf[128];
329 char dev_name[MAX_DEVICE_NAME + 1];
330 unsigned long long rd_sec_or_dummy;
331 unsigned long long wr_sec_or_dummy;
332 stats_dev_data_t *curr_data;
333 stats_dev_t *stats_dev;
290 FILE *fp; 334 FILE *fp;
291 int rc; 335 int rc;
292 int i = 0;
293 char buf[128];
294 unsigned major, minor;
295 unsigned long wr_ops, dummy; /* %*lu for suppress the conversion wouldn't work */
296 unsigned long long rd_sec_or_wr_ops;
297 unsigned long long rd_sec_or_dummy, wr_sec_or_dummy, wr_sec;
298 struct stats_dev sd;
299 336
300 fp = xfopen_for_read("/proc/diskstats"); 337 fp = xfopen_for_read("/proc/diskstats");
301
302 /* Read and possibly print stats from /proc/diskstats */ 338 /* Read and possibly print stats from /proc/diskstats */
303 while (fgets(buf, sizeof(buf), fp)) { 339 while (fgets(buf, sizeof(buf), fp)) {
304 rc = sscanf(buf, "%u %u %s %lu %llu %llu %llu %lu %lu %llu %lu %lu %lu %lu", 340 sscanf(buf, "%*s %*s %"MAX_DEVICE_NAME_STR"s", dev_name);
305 &major, &minor, sd.dname, &sd.rd_ops, 341 if (G.dev_name_list) {
306 &rd_sec_or_dummy, &rd_sec_or_wr_ops, &wr_sec_or_dummy, 342 /* Is device name in list? */
307 &wr_ops, &dummy, &wr_sec, &dummy, &dummy, &dummy, &dummy); 343 if (!llist_find_str(G.dev_name_list, dev_name))
308 344 continue;
309 switch (rc) { 345 } else if (is_partition(dev_name)) {
310 case 14: 346 continue;
311 sd.wr_ops = wr_ops;
312 sd.rd_sectors = rd_sec_or_wr_ops;
313 sd.wr_sectors = wr_sec;
314 break;
315 case 7:
316 sd.rd_sectors = rd_sec_or_dummy;
317 sd.wr_ops = (unsigned long)rd_sec_or_wr_ops;
318 sd.wr_sectors = wr_sec_or_dummy;
319 break;
320 default:
321 break;
322 } 347 }
323 348
324 if (!G.dev_list && !is_partition(sd.dname)) { 349 stats_dev = stats_dev_find_or_new(dev_name);
325 /* User didn't specify device */ 350 curr_data = &stats_dev->curr_data;
326 if (!G.show_all && !sd.rd_ops && !sd.wr_ops) { 351
327 /* Don't print unused device */ 352 rc = sscanf(buf, "%*s %*s %*s %lu %llu %llu %llu %lu %*s %llu",
328 continue; 353 &curr_data->rd_ops,
329 } 354 &rd_sec_or_dummy,
330 print_stats_dev_struct(&G.saved_stats_dev[i], &sd, itv); 355 &curr_data->rd_sectors,
331 G.saved_stats_dev[i] = sd; 356 &wr_sec_or_dummy,
332 i++; 357 &curr_data->wr_ops,
333 } else { 358 &curr_data->wr_sectors);
334 /* Is device in device list? */ 359 if (rc != 6) {
335 if (llist_find_str(G.dev_list, sd.dname)) { 360 curr_data->rd_sectors = rd_sec_or_dummy;
336 /* Print current statistics */ 361 curr_data->wr_sectors = wr_sec_or_dummy;
337 print_stats_dev_struct(&G.saved_stats_dev[i], &sd, itv); 362 //curr_data->rd_ops = ;
338 G.saved_stats_dev[i] = sd; 363 curr_data->wr_ops = (unsigned long)curr_data->rd_sectors;
339 i++;
340 } else
341 continue;
342 } 364 }
365
366 if (!G.dev_name_list /* User didn't specify device */
367 && !G.show_all
368 && curr_data->rd_ops == 0
369 && curr_data->wr_ops == 0
370 ) {
371 /* Don't print unused device */
372 continue;
373 }
374
375 /* Print current statistics */
376 print_stats_dev_struct(stats_dev, itv);
377 stats_dev->prev_data = *curr_data;
343 } 378 }
344 379
345 fclose(fp); 380 fclose(fp);
@@ -354,40 +389,10 @@ static void dev_report(cputime_t itv)
354 do_disk_statistics(itv); 389 do_disk_statistics(itv);
355} 390}
356 391
357static unsigned get_number_of_devices(void)
358{
359 FILE *fp;
360 char buf[128];
361 int rv;
362 unsigned n = 0;
363 unsigned long rd_ops, wr_ops;
364 char dname[MAX_DEVICE_NAME];
365
366 fp = xfopen_for_read("/proc/diskstats");
367
368 while (fgets(buf, sizeof(buf), fp)) {
369 rv = sscanf(buf, "%*d %*d %s %lu %*u %*u %*u %lu",
370 dname, &rd_ops, &wr_ops);
371 if (rv == 2 || is_partition(dname))
372 /* A partition */
373 continue;
374 if (!rd_ops && !wr_ops) {
375 /* Unused device */
376 if (!G.show_all)
377 continue;
378 }
379 n++;
380 }
381
382 fclose(fp);
383 return n;
384}
385
386//usage:#define iostat_trivial_usage 392//usage:#define iostat_trivial_usage
387//usage: "[-c] [-d] [-t] [-z] [-k|-m] [ALL|BLOCKDEV...] [INTERVAL [COUNT]]" 393//usage: "[-c] [-d] [-t] [-z] [-k|-m] [ALL|BLOCKDEV...] [INTERVAL [COUNT]]"
388//usage:#define iostat_full_usage "\n\n" 394//usage:#define iostat_full_usage "\n\n"
389//usage: "Report CPU and I/O statistics\n" 395//usage: "Report CPU and I/O statistics\n"
390//usage: "\nOptions:"
391//usage: "\n -c Show CPU utilization" 396//usage: "\n -c Show CPU utilization"
392//usage: "\n -d Show device utilization" 397//usage: "\n -d Show device utilization"
393//usage: "\n -t Print current time" 398//usage: "\n -t Print current time"
@@ -398,7 +403,7 @@ static unsigned get_number_of_devices(void)
398int iostat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 403int iostat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
399int iostat_main(int argc UNUSED_PARAM, char **argv) 404int iostat_main(int argc UNUSED_PARAM, char **argv)
400{ 405{
401 int opt, dev_num; 406 int opt;
402 unsigned interval; 407 unsigned interval;
403 int count; 408 int count;
404 stats_cpu_t stats_data[2]; 409 stats_cpu_t stats_data[2];
@@ -427,14 +432,12 @@ int iostat_main(int argc UNUSED_PARAM, char **argv)
427 argv += optind; 432 argv += optind;
428 433
429 /* Store device names into device list */ 434 /* Store device names into device list */
430 dev_num = 0;
431 while (*argv && !isdigit(*argv[0])) { 435 while (*argv && !isdigit(*argv[0])) {
432 if (strcmp(*argv, "ALL") != 0) { 436 if (strcmp(*argv, "ALL") != 0) {
433 /* If not ALL, save device name */ 437 /* If not ALL, save device name */
434 char *dev_name = skip_dev_pfx(*argv); 438 char *dev_name = skip_dev_pfx(*argv);
435 if (!llist_find_str(G.dev_list, dev_name)) { 439 if (!llist_find_str(G.dev_name_list, dev_name)) {
436 llist_add_to(&G.dev_list, dev_name); 440 llist_add_to(&G.dev_name_list, dev_name);
437 dev_num++;
438 } 441 }
439 } else { 442 } else {
440 G.show_all = 1; 443 G.show_all = 1;
@@ -454,13 +457,6 @@ int iostat_main(int argc UNUSED_PARAM, char **argv)
454 count = xatoi_positive(*argv); 457 count = xatoi_positive(*argv);
455 } 458 }
456 459
457 /* Allocate space for device stats */
458 if (opt & OPT_d) {
459 G.saved_stats_dev = xzalloc(sizeof(G.saved_stats_dev[0]) *
460 (dev_num ? dev_num : get_number_of_devices())
461 );
462 }
463
464 if (opt & OPT_m) { 460 if (opt & OPT_m) {
465 G.unit.str = " MB"; 461 G.unit.str = " MB";
466 G.unit.div = 2048; 462 G.unit.div = 2048;
@@ -530,8 +526,8 @@ int iostat_main(int argc UNUSED_PARAM, char **argv)
530 } 526 }
531 527
532 if (ENABLE_FEATURE_CLEAN_UP) { 528 if (ENABLE_FEATURE_CLEAN_UP) {
533 llist_free(G.dev_list, NULL); 529 llist_free(G.dev_name_list, NULL);
534 free(G.saved_stats_dev); 530 stats_dev_free(G.stats_dev_list);
535 free(&G); 531 free(&G);
536 } 532 }
537 533
diff --git a/procps/kill.c b/procps/kill.c
index fa79ce2e7..8aa0eb3e2 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -12,7 +12,6 @@
12//usage: "[-l] [-SIG] PID..." 12//usage: "[-l] [-SIG] PID..."
13//usage:#define kill_full_usage "\n\n" 13//usage:#define kill_full_usage "\n\n"
14//usage: "Send a signal (default: TERM) to given PIDs\n" 14//usage: "Send a signal (default: TERM) to given PIDs\n"
15//usage: "\nOptions:"
16//usage: "\n -l List all signal names and numbers" 15//usage: "\n -l List all signal names and numbers"
17/* //usage: "\n -s SIG Yet another way of specifying SIG" */ 16/* //usage: "\n -s SIG Yet another way of specifying SIG" */
18//usage: 17//usage:
@@ -30,7 +29,6 @@
30//usage: "[-l] [-q] [-SIG] PROCESS_NAME..." 29//usage: "[-l] [-q] [-SIG] PROCESS_NAME..."
31//usage:#define killall_full_usage "\n\n" 30//usage:#define killall_full_usage "\n\n"
32//usage: "Send a signal (default: TERM) to given processes\n" 31//usage: "Send a signal (default: TERM) to given processes\n"
33//usage: "\nOptions:"
34//usage: "\n -l List all signal names and numbers" 32//usage: "\n -l List all signal names and numbers"
35/* //usage: "\n -s SIG Yet another way of specifying SIG" */ 33/* //usage: "\n -s SIG Yet another way of specifying SIG" */
36//usage: "\n -q Don't complain if no processes were killed" 34//usage: "\n -q Don't complain if no processes were killed"
@@ -42,7 +40,6 @@
42//usage: "[-l] [-SIG] [-o PID]..." 40//usage: "[-l] [-SIG] [-o PID]..."
43//usage:#define killall5_full_usage "\n\n" 41//usage:#define killall5_full_usage "\n\n"
44//usage: "Send a signal (default: TERM) to all processes outside current session\n" 42//usage: "Send a signal (default: TERM) to all processes outside current session\n"
45//usage: "\nOptions:"
46//usage: "\n -l List all signal names and numbers" 43//usage: "\n -l List all signal names and numbers"
47//usage: "\n -o PID Don't signal this PID" 44//usage: "\n -o PID Don't signal this PID"
48/* //usage: "\n -s SIG Yet another way of specifying SIG" */ 45/* //usage: "\n -s SIG Yet another way of specifying SIG" */
diff --git a/procps/mpstat.c b/procps/mpstat.c
index da8f34dab..aa5a5c73f 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -844,7 +844,6 @@ static int get_irqcpu_nr(const char *f, int max_irqs)
844//usage: "[-A] [-I SUM|CPU|ALL|SCPU] [-u] [-P num|ALL] [INTERVAL [COUNT]]" 844//usage: "[-A] [-I SUM|CPU|ALL|SCPU] [-u] [-P num|ALL] [INTERVAL [COUNT]]"
845//usage:#define mpstat_full_usage "\n\n" 845//usage:#define mpstat_full_usage "\n\n"
846//usage: "Per-processor statistics\n" 846//usage: "Per-processor statistics\n"
847//usage: "\nOptions:"
848//usage: "\n -A Same as -I ALL -u -P ALL" 847//usage: "\n -A Same as -I ALL -u -P ALL"
849//usage: "\n -I SUM|CPU|ALL|SCPU Report interrupt statistics" 848//usage: "\n -I SUM|CPU|ALL|SCPU Report interrupt statistics"
850//usage: "\n -P num|ALL Processor to monitor" 849//usage: "\n -P num|ALL Processor to monitor"
diff --git a/procps/pgrep.c b/procps/pgrep.c
index 902a3a75e..dc7ffff48 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -11,7 +11,6 @@
11//usage: "[-flnovx] [-s SID|-P PPID|PATTERN]" 11//usage: "[-flnovx] [-s SID|-P PPID|PATTERN]"
12//usage:#define pgrep_full_usage "\n\n" 12//usage:#define pgrep_full_usage "\n\n"
13//usage: "Display process(es) selected by regex PATTERN\n" 13//usage: "Display process(es) selected by regex PATTERN\n"
14//usage: "\nOptions:"
15//usage: "\n -l Show command name too" 14//usage: "\n -l Show command name too"
16//usage: "\n -f Match against entire command line" 15//usage: "\n -f Match against entire command line"
17//usage: "\n -n Show the newest process only" 16//usage: "\n -n Show the newest process only"
@@ -25,7 +24,6 @@
25//usage: "[-l|-SIGNAL] [-fnovx] [-s SID|-P PPID|PATTERN]" 24//usage: "[-l|-SIGNAL] [-fnovx] [-s SID|-P PPID|PATTERN]"
26//usage:#define pkill_full_usage "\n\n" 25//usage:#define pkill_full_usage "\n\n"
27//usage: "Send a signal to process(es) selected by regex PATTERN\n" 26//usage: "Send a signal to process(es) selected by regex PATTERN\n"
28//usage: "\nOptions:"
29//usage: "\n -l List all signals" 27//usage: "\n -l List all signals"
30//usage: "\n -f Match against entire command line" 28//usage: "\n -f Match against entire command line"
31//usage: "\n -n Signal the newest process only" 29//usage: "\n -n Signal the newest process only"
@@ -130,7 +128,7 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
130 bb_show_usage(); 128 bb_show_usage();
131 129
132 if (argv[0]) 130 if (argv[0])
133 xregcomp(&re_buffer, argv[0], 0); 131 xregcomp(&re_buffer, argv[0], REG_EXTENDED | REG_NOSUB);
134 132
135 matched_pid = 0; 133 matched_pid = 0;
136 cmd_last = NULL; 134 cmd_last = NULL;
diff --git a/procps/pidof.c b/procps/pidof.c
index e102a31c6..6d7b59109 100644
--- a/procps/pidof.c
+++ b/procps/pidof.c
@@ -10,7 +10,7 @@
10//usage:#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT) 10//usage:#if (ENABLE_FEATURE_PIDOF_SINGLE || ENABLE_FEATURE_PIDOF_OMIT)
11//usage:#define pidof_trivial_usage 11//usage:#define pidof_trivial_usage
12//usage: "[OPTIONS] [NAME]..." 12//usage: "[OPTIONS] [NAME]..."
13//usage:#define USAGE_PIDOF "\n\nOptions:" 13//usage:#define USAGE_PIDOF "\n"
14//usage:#else 14//usage:#else
15//usage:#define pidof_trivial_usage 15//usage:#define pidof_trivial_usage
16//usage: "[NAME]..." 16//usage: "[NAME]..."
diff --git a/procps/pmap.c b/procps/pmap.c
index 7f7f391b9..fd995a54d 100644
--- a/procps/pmap.c
+++ b/procps/pmap.c
@@ -8,22 +8,22 @@
8 * for details. 8 * for details.
9 */ 9 */
10 10
11//applet:IF_PMAP(APPLET(pmap, BB_DIR_USR_BIN, BB_SUID_DROP))
12//kbuild:lib-$(CONFIG_PMAP) += pmap.o
13
14//config:config PMAP 11//config:config PMAP
15//config: bool "pmap" 12//config: bool "pmap"
16//config: default y 13//config: default y
17//config: help 14//config: help
18//config: Display processes' memory mappings. 15//config: Display processes' memory mappings.
19 16
17//applet:IF_PMAP(APPLET(pmap, BB_DIR_USR_BIN, BB_SUID_DROP))
18//kbuild:lib-$(CONFIG_PMAP) += pmap.o
19
20//usage:#define pmap_trivial_usage 20//usage:#define pmap_trivial_usage
21//usage: "[-x][-q] PID" 21//usage: "[-xq] PID"
22//usage:#define pmap_full_usage "\n\n" 22//usage:#define pmap_full_usage "\n\n"
23//usage: "Display detailed precesses' memory usage\n" 23//usage: "Display detailed process memory usage"
24//usage: "\nOptions:" 24//usage: "\n"
25//usage: "\n -x show details" 25//usage: "\n -x Show details"
26//usage: "\n -q quiet" 26//usage: "\n -q Quiet"
27 27
28#include "libbb.h" 28#include "libbb.h"
29 29
diff --git a/procps/ps.c b/procps/ps.c
index 41e1b1e87..41124279d 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -15,7 +15,6 @@
15//usage: "[-o COL1,COL2=HEADER]" IF_FEATURE_SHOW_THREADS(" [-T]") 15//usage: "[-o COL1,COL2=HEADER]" IF_FEATURE_SHOW_THREADS(" [-T]")
16//usage:#define ps_full_usage "\n\n" 16//usage:#define ps_full_usage "\n\n"
17//usage: "Show list of processes\n" 17//usage: "Show list of processes\n"
18//usage: "\nOptions:"
19//usage: "\n -o COL1,COL2=HEADER Select columns for display" 18//usage: "\n -o COL1,COL2=HEADER Select columns for display"
20//usage: IF_FEATURE_SHOW_THREADS( 19//usage: IF_FEATURE_SHOW_THREADS(
21//usage: "\n -T Show threads" 20//usage: "\n -T Show threads"
@@ -26,7 +25,7 @@
26//usage:#if !ENABLE_SELINUX && !ENABLE_FEATURE_PS_WIDE 25//usage:#if !ENABLE_SELINUX && !ENABLE_FEATURE_PS_WIDE
27//usage:#define USAGE_PS "\nThis version of ps accepts no options" 26//usage:#define USAGE_PS "\nThis version of ps accepts no options"
28//usage:#else 27//usage:#else
29//usage:#define USAGE_PS "\nOptions:" 28//usage:#define USAGE_PS ""
30//usage:#endif 29//usage:#endif
31//usage: 30//usage:
32//usage:#define ps_trivial_usage 31//usage:#define ps_trivial_usage
@@ -88,15 +87,6 @@ enum { MAX_WIDTH = 2*1024 };
88 * TIME The cumulative execution time for the process 87 * TIME The cumulative execution time for the process
89 * CMD The command name; the full command line is shown with -f 88 * CMD The command name; the full command line is shown with -f
90 */ 89 */
91#if ENABLE_SELINUX
92# define SELINUX_O_PREFIX "label,"
93# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args")
94#elif ENABLE_PLATFORM_MINGW32
95# define DEFAULT_O_STR ("pid,comm")
96#else
97# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args")
98#endif
99
100typedef struct { 90typedef struct {
101 uint16_t width; 91 uint16_t width;
102 char name6[6]; 92 char name6[6];
@@ -116,7 +106,6 @@ struct globals {
116 unsigned kernel_HZ; 106 unsigned kernel_HZ;
117 unsigned long long seconds_since_boot; 107 unsigned long long seconds_since_boot;
118#endif 108#endif
119 char default_o[sizeof(DEFAULT_O_STR)];
120} FIX_ALIASING; 109} FIX_ALIASING;
121#define G (*(struct globals*)&bb_common_bufsiz1) 110#define G (*(struct globals*)&bb_common_bufsiz1)
122#define out (G.out ) 111#define out (G.out )
@@ -127,7 +116,6 @@ struct globals {
127#define terminal_width (G.terminal_width ) 116#define terminal_width (G.terminal_width )
128#define kernel_HZ (G.kernel_HZ ) 117#define kernel_HZ (G.kernel_HZ )
129#define seconds_since_boot (G.seconds_since_boot) 118#define seconds_since_boot (G.seconds_since_boot)
130#define default_o (G.default_o )
131#define INIT_G() do { } while (0) 119#define INIT_G() do { } while (0)
132 120
133#if ENABLE_FEATURE_PS_TIME 121#if ENABLE_FEATURE_PS_TIME
@@ -253,7 +241,7 @@ static void func_comm(char *buf, int size, const procps_status_t *ps)
253 safe_strncpy(buf, ps->comm, size+1); 241 safe_strncpy(buf, ps->comm, size+1);
254} 242}
255 243
256static void func_stat(char *buf, int size, const procps_status_t *ps) 244static void func_state(char *buf, int size, const procps_status_t *ps)
257{ 245{
258 safe_strncpy(buf, ps->state, size+1); 246 safe_strncpy(buf, ps->state, size+1);
259} 247}
@@ -404,7 +392,7 @@ static const ps_out_t out_spec[] = {
404 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY }, 392 { 6 , "tty" ,"TT" ,func_tty ,PSSCAN_TTY },
405 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ }, 393 { 4 , "vsz" ,"VSZ" ,func_vsz ,PSSCAN_VSZ },
406/* Not mandated, but useful: */ 394/* Not mandated, but useful: */
407 { 4 , "stat" ,"STAT" ,func_stat ,PSSCAN_STAT }, 395 { 4 , "stat" ,"STAT" ,func_state ,PSSCAN_STATE },
408 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS }, 396 { 4 , "rss" ,"RSS" ,func_rss ,PSSCAN_RSS },
409#endif 397#endif
410#if ENABLE_SELINUX 398#if ENABLE_SELINUX
@@ -542,11 +530,21 @@ static void format_process(const procps_status_t *ps)
542 printf("%.*s\n", terminal_width, buffer); 530 printf("%.*s\n", terminal_width, buffer);
543} 531}
544 532
533#if ENABLE_SELINUX
534# define SELINUX_O_PREFIX "label,"
535# define DEFAULT_O_STR (SELINUX_O_PREFIX "pid,user" IF_FEATURE_PS_TIME(",time") ",args")
536#elif ENABLE_PLATFORM_MINGW32
537# define DEFAULT_O_STR ("pid,comm")
538#else
539# define DEFAULT_O_STR ("pid,user" IF_FEATURE_PS_TIME(",time") ",args")
540#endif
541
545int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 542int ps_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
546int ps_main(int argc UNUSED_PARAM, char **argv) 543int ps_main(int argc UNUSED_PARAM, char **argv)
547{ 544{
548 procps_status_t *p; 545 procps_status_t *p;
549 llist_t* opt_o = NULL; 546 llist_t* opt_o = NULL;
547 char default_o[sizeof(DEFAULT_O_STR)];
550 int opt; 548 int opt;
551 enum { 549 enum {
552 OPT_Z = (1 << 0), 550 OPT_Z = (1 << 0),
@@ -584,7 +582,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv)
584 parse_o(llist_pop(&opt_o)); 582 parse_o(llist_pop(&opt_o));
585 } while (opt_o); 583 } while (opt_o);
586 } else { 584 } else {
587 /* Below: parse_o() needs char*, NOT const char*... */ 585 /* Below: parse_o() needs char*, NOT const char*, can't give it default_o */
588#if ENABLE_SELINUX 586#if ENABLE_SELINUX
589 if (!(opt & OPT_Z) || !is_selinux_enabled()) { 587 if (!(opt & OPT_Z) || !is_selinux_enabled()) {
590 /* no -Z or no SELinux: do not show LABEL */ 588 /* no -Z or no SELinux: do not show LABEL */
diff --git a/procps/pstree.c b/procps/pstree.c
index 16649cfaa..8ba30795d 100644
--- a/procps/pstree.c
+++ b/procps/pstree.c
@@ -24,7 +24,6 @@
24//usage: "[-p] [PID|USER]" 24//usage: "[-p] [PID|USER]"
25//usage:#define pstree_full_usage "\n\n" 25//usage:#define pstree_full_usage "\n\n"
26//usage: "Display process tree, optionally start from USER or PID\n" 26//usage: "Display process tree, optionally start from USER or PID\n"
27//usage: "\nOptions:"
28//usage: "\n -p Show pids" 27//usage: "\n -p Show pids"
29 28
30#include "libbb.h" 29#include "libbb.h"
diff --git a/procps/renice.c b/procps/renice.c
index 067c8f75a..77f400a1d 100644
--- a/procps/renice.c
+++ b/procps/renice.c
@@ -23,7 +23,6 @@
23//usage: "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]" 23//usage: "{{-n INCREMENT} | PRIORITY} [[-p | -g | -u] ID...]"
24//usage:#define renice_full_usage "\n\n" 24//usage:#define renice_full_usage "\n\n"
25//usage: "Change scheduling priority for a running process\n" 25//usage: "Change scheduling priority for a running process\n"
26//usage: "\nOptions:"
27//usage: "\n -n Adjust current nice value (smaller is faster)" 26//usage: "\n -n Adjust current nice value (smaller is faster)"
28//usage: "\n -p Process id(s) (default)" 27//usage: "\n -p Process id(s) (default)"
29//usage: "\n -g Process group id(s)" 28//usage: "\n -g Process group id(s)"
diff --git a/procps/sysctl.c b/procps/sysctl.c
index f36548f87..cb3b6a25a 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -15,7 +15,6 @@
15//usage: "[OPTIONS] [VALUE]..." 15//usage: "[OPTIONS] [VALUE]..."
16//usage:#define sysctl_full_usage "\n\n" 16//usage:#define sysctl_full_usage "\n\n"
17//usage: "Configure kernel parameters at runtime\n" 17//usage: "Configure kernel parameters at runtime\n"
18//usage: "\nOptions:"
19//usage: "\n -n Don't print key names" 18//usage: "\n -n Don't print key names"
20//usage: "\n -e Don't warn about unknown keys" 19//usage: "\n -e Don't warn about unknown keys"
21//usage: "\n -w Change sysctl setting" 20//usage: "\n -w Change sysctl setting"
diff --git a/procps/watch.c b/procps/watch.c
index e289bf8cb..36af1cca7 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -15,7 +15,6 @@
15//usage: "[-n SEC] [-t] PROG ARGS" 15//usage: "[-n SEC] [-t] PROG ARGS"
16//usage:#define watch_full_usage "\n\n" 16//usage:#define watch_full_usage "\n\n"
17//usage: "Run PROG periodically\n" 17//usage: "Run PROG periodically\n"
18//usage: "\nOptions:"
19//usage: "\n -n Loop period in seconds (default 2)" 18//usage: "\n -n Loop period in seconds (default 2)"
20//usage: "\n -t Don't print header" 19//usage: "\n -t Don't print header"
21//usage: 20//usage: