aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-06-28 07:46:32 +0100
committerRon Yorston <rmy@pobox.com>2021-06-28 07:46:32 +0100
commite1ad66c0b8fd58a7158d40771175a7dab224202d (patch)
tree959d687eee9637151ad5798322586174de331141 /procps
parent0fdf99bee07b6c38795eb5415b5e337ab82cfba8 (diff)
parent5dbbd0a6f52befe6bc57baf97d39168e595197f1 (diff)
downloadbusybox-w32-e1ad66c0b8fd58a7158d40771175a7dab224202d.tar.gz
busybox-w32-e1ad66c0b8fd58a7158d40771175a7dab224202d.tar.bz2
busybox-w32-e1ad66c0b8fd58a7158d40771175a7dab224202d.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'procps')
-rw-r--r--procps/free.c86
-rw-r--r--procps/kill.c2
-rw-r--r--procps/lsof.c2
-rw-r--r--procps/pgrep.c12
-rw-r--r--procps/sysctl.c4
-rw-r--r--procps/top.c4
-rw-r--r--procps/watch.c2
7 files changed, 64 insertions, 48 deletions
diff --git a/procps/free.c b/procps/free.c
index 142786083..f19c38dd5 100644
--- a/procps/free.c
+++ b/procps/free.c
@@ -19,9 +19,9 @@
19//kbuild:lib-$(CONFIG_FREE) += free.o 19//kbuild:lib-$(CONFIG_FREE) += free.o
20 20
21//usage:#define free_trivial_usage 21//usage:#define free_trivial_usage
22//usage: "" IF_DESKTOP("[-b/k/m/g]") 22//usage: "" IF_DESKTOP("[-bkmgh]")
23//usage:#define free_full_usage "\n\n" 23//usage:#define free_full_usage "\n\n"
24//usage: "Display the amount of free and used system memory" 24//usage: "Display free and used memory"
25//usage: 25//usage:
26//usage:#define free_example_usage 26//usage:#define free_example_usage
27//usage: "$ free\n" 27//usage: "$ free\n"
@@ -29,6 +29,27 @@
29//usage: " Mem: 257628 248724 8904 59644 93124\n" 29//usage: " Mem: 257628 248724 8904 59644 93124\n"
30//usage: " Swap: 128516 8404 120112\n" 30//usage: " Swap: 128516 8404 120112\n"
31//usage: "Total: 386144 257128 129016\n" 31//usage: "Total: 386144 257128 129016\n"
32//procps-ng 3.3.15:
33// -b, --bytes show output in bytes
34// --kilo show output in kilobytes
35// --mega show output in megabytes
36// --giga show output in gigabytes
37// --tera show output in terabytes
38// --peta show output in petabytes
39// -k, --kibi show output in kibibytes
40// -m, --mebi show output in mebibytes
41// -g, --gibi show output in gibibytes
42// --tebi show output in tebibytes
43// --pebi show output in pebibytes
44// -h, --human show human-readable output
45// --si use powers of 1000 not 1024
46// -l, --lohi show detailed low and high memory statistics
47// -t, --total show total for RAM + swap
48// -s N, --seconds N repeat printing every N seconds
49// -c N, --count N repeat printing N times, then exit
50// -w, --wide wide output
51//
52//NB: if we implement -s or -c, need to stop being NOFORK!
32 53
33#include "libbb.h" 54#include "libbb.h"
34#ifdef __linux__ 55#ifdef __linux__
@@ -38,18 +59,22 @@
38struct globals { 59struct globals {
39 unsigned mem_unit; 60 unsigned mem_unit;
40#if ENABLE_DESKTOP 61#if ENABLE_DESKTOP
41 uint8_t unit_steps; 62 unsigned unit;
42# define G_unit_steps g->unit_steps 63# define G_unit g->unit
43#else 64#else
44# define G_unit_steps 10 65# define G_unit (1 << 10)
45#endif 66#endif
46 unsigned long cached_kb, available_kb, reclaimable_kb; 67 unsigned long cached_kb, available_kb, reclaimable_kb;
47}; 68};
48/* Because of NOFORK, "globals" are not in global data */ 69/* Because of NOFORK, "globals" are not in global data */
49 70
50static unsigned long long scale(struct globals *g, unsigned long d) 71static const char *scale(struct globals *g, unsigned long d)
51{ 72{
52 return ((unsigned long long)d * g->mem_unit) >> G_unit_steps; 73 /* Display (size * block_size) with one decimal digit.
74 * If display_unit == 0, show value no bigger than 1024 with suffix (K,M,G...),
75 * else divide by display_unit and do not use suffix.
76 * Returns "auto pointer" */
77 return make_human_readable_str(d, g->mem_unit, G_unit);
53} 78}
54 79
55#if !ENABLE_PLATFORM_MINGW32 80#if !ENABLE_PLATFORM_MINGW32
@@ -97,20 +122,27 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
97 int seen_available; 122 int seen_available;
98 123
99#if ENABLE_DESKTOP 124#if ENABLE_DESKTOP
100 G.unit_steps = 10; 125 G.unit = 1 << 10;
101 if (argv[1] && argv[1][0] == '-') { 126 if (argv[1] && argv[1][0] == '-') {
102 switch (argv[1][1]) { 127 switch (argv[1][1]) {
103 case 'b': 128 case 'b':
104 G.unit_steps = 0; 129 G.unit = 1;
105 break; 130 break;
106 case 'k': /* 2^10 */ 131 case 'k': /* 2^10 */
107 /* G.unit_steps = 10; - already is */ 132 /* G.unit = 1 << 10; - already is */
108 break; 133 break;
109 case 'm': /* 2^20 */ 134 case 'm': /* 2^20 */
110 G.unit_steps = 20; 135 G.unit = 1 << 20;
111 break; 136 break;
112 case 'g': /* 2^30 */ 137 case 'g': /* 2^30 */
113 G.unit_steps = 30; 138 G.unit = 1 << 30;
139 break;
140// case 't':
141// -- WRONG, -t is not "terabytes" in procps-ng, it's --total
142// G.unit = 1 << 40;
143// break;
144 case 'h':
145 G.unit = 0; /* human readable */
114 break; 146 break;
115 default: 147 default:
116 bb_show_usage(); 148 bb_show_usage();
@@ -135,29 +167,13 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
135 cached += ((unsigned long long) G.reclaimable_kb * 1024) / G.mem_unit; 167 cached += ((unsigned long long) G.reclaimable_kb * 1024) / G.mem_unit;
136 cached_plus_free = cached + info.freeram; 168 cached_plus_free = cached + info.freeram;
137 169
138/* In case (long long * G.mem_unit) can overflow, this can be used to reduce the chances */ 170 printf("%12s%12s%12s",
139#if 0 //ENABLE_DESKTOP
140 while (!(G.mem_unit & 1) && G.unit_steps != 0) {
141 G.mem_unit >>= 1;
142 G.unit_steps--;
143 //bb_error_msg("mem_unit:%d unit_steps:%d", G.mem_unit, G.unit_steps);
144 }
145#endif
146
147#if !ENABLE_PLATFORM_MINGW32
148#define FIELDS_6 "%12llu %11llu %11llu %11llu %11llu %11llu\n"
149#define FIELDS_3 (FIELDS_6 + 6 + 7 + 7)
150#define FIELDS_2 (FIELDS_6 + 6 + 7 + 7 + 7)
151#else
152#define FIELDS_6 "%12I64u %11I64u %11I64u %11I64u %11I64u %11I64u\n"
153#define FIELDS_3 (FIELDS_6 + 7 + 8 + 8)
154#define FIELDS_2 (FIELDS_6 + 8 + 8 + 8 + 8)
155#endif
156
157 printf(FIELDS_6,
158 scale(&G, info.totalram), //total 171 scale(&G, info.totalram), //total
159 scale(&G, info.totalram - cached_plus_free), //used 172 scale(&G, info.totalram - cached_plus_free), //used
160 scale(&G, info.freeram), //free 173 scale(&G, info.freeram) //free
174 );
175 /* using two printf's: only 4 auto strings are supported, we need 6 */
176 printf("%12s%12s%12s\n",
161 scale(&G, info.sharedram), //shared 177 scale(&G, info.sharedram), //shared
162 scale(&G, cached), //buff/cache 178 scale(&G, cached), //buff/cache
163 scale(&G, available) //available 179 scale(&G, available) //available
@@ -167,14 +183,14 @@ int free_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
167 * buffer cache as free memory. */ 183 * buffer cache as free memory. */
168 if (!seen_available) { 184 if (!seen_available) {
169 printf("-/+ buffers/cache: "); 185 printf("-/+ buffers/cache: ");
170 printf(FIELDS_2, 186 printf("%12s%12s%12s\n" + 4,
171 scale(&G, info.totalram - cached_plus_free), //used 187 scale(&G, info.totalram - cached_plus_free), //used
172 scale(&G, cached_plus_free) //free 188 scale(&G, cached_plus_free) //free
173 ); 189 );
174 } 190 }
175#if BB_MMU 191#if BB_MMU
176 printf("Swap: "); 192 printf("Swap: ");
177 printf(FIELDS_3, 193 printf("%12s%12s%12s\n",
178 scale(&G, info.totalswap), //total 194 scale(&G, info.totalswap), //total
179 scale(&G, info.totalswap - info.freeswap), //used 195 scale(&G, info.totalswap - info.freeswap), //used
180 scale(&G, info.freeswap) //free 196 scale(&G, info.freeswap) //free
diff --git a/procps/kill.c b/procps/kill.c
index 358d8f42b..8c2bc2b6f 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -59,7 +59,7 @@
59//usage: "$ kill 252\n" 59//usage: "$ kill 252\n"
60//usage: 60//usage:
61//usage:#define killall_trivial_usage 61//usage:#define killall_trivial_usage
62//usage: "[-l] [-q] [-SIG] PROCESS_NAME..." 62//usage: "[-lq] [-SIG] PROCESS_NAME..."
63//usage:#define killall_full_usage "\n\n" 63//usage:#define killall_full_usage "\n\n"
64//usage: "Send a signal (default: TERM) to given processes\n" 64//usage: "Send a signal (default: TERM) to given processes\n"
65//usage: "\n -l List all signal names and numbers" 65//usage: "\n -l List all signal names and numbers"
diff --git a/procps/lsof.c b/procps/lsof.c
index 21ac85ed3..9cb8d066c 100644
--- a/procps/lsof.c
+++ b/procps/lsof.c
@@ -66,7 +66,7 @@ int lsof_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
66 66
67 safe_strncpy(name + baseofs, entry->d_name, 10); 67 safe_strncpy(name + baseofs, entry->d_name, 10);
68 if ((fdlink = xmalloc_readlink(name)) != NULL) { 68 if ((fdlink = xmalloc_readlink(name)) != NULL) {
69 printf("%d\t%s\t%s\n", proc->pid, proc->exe, fdlink); 69 printf("%d\t%s\t%s\t%s\n", proc->pid, proc->exe, entry->d_name, fdlink);
70 free(fdlink); 70 free(fdlink);
71 } 71 }
72 } 72 }
diff --git a/procps/pgrep.c b/procps/pgrep.c
index 495e0ef9d..6d25c247e 100644
--- a/procps/pgrep.c
+++ b/procps/pgrep.c
@@ -44,17 +44,17 @@
44//usage: "\n -P Match parent process ID" 44//usage: "\n -P Match parent process ID"
45//usage: 45//usage:
46//usage:#define pkill_trivial_usage 46//usage:#define pkill_trivial_usage
47//usage: "[-l|-SIGNAL] [-fnovx] [-s SID|-P PPID|PATTERN]" 47//usage: "[-l|-SIGNAL] [-xfvno] [-s SID|-P PPID|PATTERN]"
48//usage:#define pkill_full_usage "\n\n" 48//usage:#define pkill_full_usage "\n\n"
49//usage: "Send a signal to process(es) selected by regex PATTERN\n" 49//usage: "Send signal to processes selected by regex PATTERN\n"
50//usage: "\n -l List all signals" 50//usage: "\n -l List all signals"
51//usage: "\n -x Match whole name (not substring)"
51//usage: "\n -f Match against entire command line" 52//usage: "\n -f Match against entire command line"
53//usage: "\n -s SID Match session ID (0 for current)"
54//usage: "\n -P PPID Match parent process ID"
55//usage: "\n -v Negate the match"
52//usage: "\n -n Signal the newest process only" 56//usage: "\n -n Signal the newest process only"
53//usage: "\n -o Signal the oldest process only" 57//usage: "\n -o Signal the oldest process only"
54//usage: "\n -v Negate the match"
55//usage: "\n -x Match whole name (not substring)"
56//usage: "\n -s Match session ID (0 for current)"
57//usage: "\n -P Match parent process ID"
58 58
59#include "libbb.h" 59#include "libbb.h"
60#include "xregex.h" 60#include "xregex.h"
diff --git a/procps/sysctl.c b/procps/sysctl.c
index e16b119e9..40afa0c90 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -21,16 +21,16 @@
21//kbuild:lib-$(CONFIG_BB_SYSCTL) += sysctl.o 21//kbuild:lib-$(CONFIG_BB_SYSCTL) += sysctl.o
22 22
23//usage:#define sysctl_trivial_usage 23//usage:#define sysctl_trivial_usage
24//usage: "-p [-enq] [FILE...] / [-enqaw] [KEY[=VALUE]]..." 24//usage: "[-enq] { -a | -p [FILE]... | [-w] [KEY[=VALUE]]... }"
25//usage:#define sysctl_full_usage "\n\n" 25//usage:#define sysctl_full_usage "\n\n"
26//usage: "Show/set kernel parameters\n" 26//usage: "Show/set kernel parameters\n"
27//usage: "\n -p Set values from FILEs (default /etc/sysctl.conf)"
28//usage: "\n -e Don't warn about unknown keys" 27//usage: "\n -e Don't warn about unknown keys"
29//usage: "\n -n Don't show key names" 28//usage: "\n -n Don't show key names"
30//usage: "\n -q Quiet" 29//usage: "\n -q Quiet"
31//usage: "\n -a Show all values" 30//usage: "\n -a Show all values"
32/* Same as -a, no need to show it */ 31/* Same as -a, no need to show it */
33/* //usage: "\n -A Show all values in table form" */ 32/* //usage: "\n -A Show all values in table form" */
33//usage: "\n -p Set values from FILEs (default /etc/sysctl.conf)"
34//usage: "\n -w Set values" 34//usage: "\n -w Set values"
35//usage: 35//usage:
36//usage:#define sysctl_example_usage 36//usage:#define sysctl_example_usage
diff --git a/procps/top.c b/procps/top.c
index cadc4ecec..4cd545c69 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -1052,9 +1052,9 @@ static unsigned handle_input(unsigned scan_mask, duration_t interval)
1052//usage: "[-b"IF_FEATURE_TOPMEM("m")IF_FEATURE_SHOW_THREADS("H")"]" 1052//usage: "[-b"IF_FEATURE_TOPMEM("m")IF_FEATURE_SHOW_THREADS("H")"]"
1053//usage: " [-n COUNT] [-d SECONDS]" 1053//usage: " [-n COUNT] [-d SECONDS]"
1054//usage:#define top_full_usage "\n\n" 1054//usage:#define top_full_usage "\n\n"
1055//usage: "Provide a view of process activity in real time." 1055//usage: "Show a view of process activity in real time."
1056//usage: "\n""Read the status of all processes from /proc each SECONDS" 1056//usage: "\n""Read the status of all processes from /proc each SECONDS"
1057//usage: "\n""and display a screenful of them." 1057//usage: "\n""and show a screenful of them."
1058//usage: "\n" 1058//usage: "\n"
1059//usage: IF_FEATURE_TOP_INTERACTIVE( 1059//usage: IF_FEATURE_TOP_INTERACTIVE(
1060//usage: "Keys:" 1060//usage: "Keys:"
diff --git a/procps/watch.c b/procps/watch.c
index 059eb1dda..1190b29df 100644
--- a/procps/watch.c
+++ b/procps/watch.c
@@ -22,7 +22,7 @@
22//usage: "[-n SEC] [-t] PROG ARGS" 22//usage: "[-n SEC] [-t] PROG ARGS"
23//usage:#define watch_full_usage "\n\n" 23//usage:#define watch_full_usage "\n\n"
24//usage: "Run PROG periodically\n" 24//usage: "Run PROG periodically\n"
25//usage: "\n -n SEC Loop period (default 2)" 25//usage: "\n -n SEC Period (default 2)"
26//usage: "\n -t Don't print header" 26//usage: "\n -t Don't print header"
27//usage: 27//usage:
28//usage:#define watch_example_usage 28//usage:#define watch_example_usage