aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-14 12:47:25 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-09-14 12:47:25 +1000
commit9df56f96fd9a213189ca94c1fccfc3c42bd9c16a (patch)
treedb1db005b59e2b78d5daf9527fa8fc604e07e8c4 /procps
parent30c62e541a1484fedc3d689d62f96d246a28b147 (diff)
parent5f3303712ef483d270097cae4ba0a559b1056121 (diff)
downloadbusybox-w32-9df56f96fd9a213189ca94c1fccfc3c42bd9c16a.tar.gz
busybox-w32-9df56f96fd9a213189ca94c1fccfc3c42bd9c16a.tar.bz2
busybox-w32-9df56f96fd9a213189ca94c1fccfc3c42bd9c16a.zip
Merge branch 'origin/master' (early part)
Diffstat (limited to 'procps')
-rw-r--r--procps/Config.src (renamed from procps/Config.in)50
-rw-r--r--procps/Kbuild.src (renamed from procps/Kbuild)0
-rw-r--r--procps/top.c149
3 files changed, 79 insertions, 120 deletions
diff --git a/procps/Config.in b/procps/Config.src
index 6a9a36638..01f6b0cf9 100644
--- a/procps/Config.in
+++ b/procps/Config.src
@@ -7,7 +7,7 @@ menu "Process Utilities"
7 7
8config FREE 8config FREE
9 bool "free" 9 bool "free"
10 default n 10 default y
11 help 11 help
12 free displays the total amount of free and used physical and swap 12 free displays the total amount of free and used physical and swap
13 memory in the system, as well as the buffers used by the kernel. 13 memory in the system, as well as the buffers used by the kernel.
@@ -15,7 +15,7 @@ config FREE
15 15
16config FUSER 16config FUSER
17 bool "fuser" 17 bool "fuser"
18 default n 18 default y
19 help 19 help
20 fuser lists all PIDs (Process IDs) that currently have a given 20 fuser lists all PIDs (Process IDs) that currently have a given
21 file open. fuser can also list all PIDs that have a given network 21 file open. fuser can also list all PIDs that have a given network
@@ -23,7 +23,7 @@ config FUSER
23 23
24config KILL 24config KILL
25 bool "kill" 25 bool "kill"
26 default n 26 default y
27 help 27 help
28 The command kill sends the specified signal to the specified 28 The command kill sends the specified signal to the specified
29 process or process group. If no signal is specified, the TERM 29 process or process group. If no signal is specified, the TERM
@@ -31,7 +31,7 @@ config KILL
31 31
32config KILLALL 32config KILLALL
33 bool "killall" 33 bool "killall"
34 default n 34 default y
35 depends on KILL 35 depends on KILL
36 help 36 help
37 killall sends a signal to all processes running any of the 37 killall sends a signal to all processes running any of the
@@ -40,38 +40,38 @@ config KILLALL
40 40
41config KILLALL5 41config KILLALL5
42 bool "killall5" 42 bool "killall5"
43 default n 43 default y
44 depends on KILL 44 depends on KILL
45 45
46config NMETER 46config NMETER
47 bool "nmeter" 47 bool "nmeter"
48 default n 48 default y
49 help 49 help
50 Prints selected system stats continuously, one line per update. 50 Prints selected system stats continuously, one line per update.
51 51
52config PGREP 52config PGREP
53 bool "pgrep" 53 bool "pgrep"
54 default n 54 default y
55 help 55 help
56 Look for processes by name. 56 Look for processes by name.
57 57
58config PIDOF 58config PIDOF
59 bool "pidof" 59 bool "pidof"
60 default n 60 default y
61 help 61 help
62 Pidof finds the process id's (pids) of the named programs. It prints 62 Pidof finds the process id's (pids) of the named programs. It prints
63 those id's on the standard output. 63 those id's on the standard output.
64 64
65config FEATURE_PIDOF_SINGLE 65config FEATURE_PIDOF_SINGLE
66 bool "Enable argument for single shot (-s)" 66 bool "Enable argument for single shot (-s)"
67 default n 67 default y
68 depends on PIDOF 68 depends on PIDOF
69 help 69 help
70 Support argument '-s' for returning only the first pid found. 70 Support argument '-s' for returning only the first pid found.
71 71
72config FEATURE_PIDOF_OMIT 72config FEATURE_PIDOF_OMIT
73 bool "Enable argument for omitting pids (-o)" 73 bool "Enable argument for omitting pids (-o)"
74 default n 74 default y
75 depends on PIDOF 75 depends on PIDOF
76 help 76 help
77 Support argument '-o' for omitting the given pids in output. 77 Support argument '-o' for omitting the given pids in output.
@@ -80,19 +80,19 @@ config FEATURE_PIDOF_OMIT
80 80
81config PKILL 81config PKILL
82 bool "pkill" 82 bool "pkill"
83 default n 83 default y
84 help 84 help
85 Send signals to processes by name. 85 Send signals to processes by name.
86 86
87config PS 87config PS
88 bool "ps" 88 bool "ps"
89 default n 89 default y
90 help 90 help
91 ps gives a snapshot of the current processes. 91 ps gives a snapshot of the current processes.
92 92
93config FEATURE_PS_WIDE 93config FEATURE_PS_WIDE
94 bool "Enable wide output option (-w)" 94 bool "Enable wide output option (-w)"
95 default n 95 default y
96 depends on PS 96 depends on PS
97 help 97 help
98 Support argument 'w' for wide output. 98 Support argument 'w' for wide output.
@@ -101,14 +101,14 @@ config FEATURE_PS_WIDE
101 101
102config FEATURE_PS_TIME 102config FEATURE_PS_TIME
103 bool "Enable time and elapsed time output" 103 bool "Enable time and elapsed time output"
104 default n 104 default y
105 depends on PS && DESKTOP 105 depends on PS && DESKTOP
106 help 106 help
107 Support -o time and -o etime output specifiers. 107 Support -o time and -o etime output specifiers.
108 108
109config FEATURE_PS_ADDITIONAL_COLUMNS 109config FEATURE_PS_ADDITIONAL_COLUMNS
110 bool "Enable additional ps columns" 110 bool "Enable additional ps columns"
111 default n 111 default y
112 depends on PS && DESKTOP 112 depends on PS && DESKTOP
113 help 113 help
114 Support -o rgroup, -o ruser, -o nice output specifiers. 114 Support -o rgroup, -o ruser, -o nice output specifiers.
@@ -123,20 +123,20 @@ config FEATURE_PS_UNUSUAL_SYSTEMS
123 123
124config RENICE 124config RENICE
125 bool "renice" 125 bool "renice"
126 default n 126 default y
127 help 127 help
128 Renice alters the scheduling priority of one or more running 128 Renice alters the scheduling priority of one or more running
129 processes. 129 processes.
130 130
131config BB_SYSCTL 131config BB_SYSCTL
132 bool "sysctl" 132 bool "sysctl"
133 default n 133 default y
134 help 134 help
135 Configure kernel parameters at runtime. 135 Configure kernel parameters at runtime.
136 136
137config TOP 137config TOP
138 bool "top" 138 bool "top"
139 default n 139 default y
140 help 140 help
141 The top program provides a dynamic real-time view of a running 141 The top program provides a dynamic real-time view of a running
142 system. 142 system.
@@ -159,7 +159,7 @@ config FEATURE_TOP_CPU_GLOBAL_PERCENTS
159 159
160config FEATURE_TOP_SMP_CPU 160config FEATURE_TOP_SMP_CPU
161 bool "SMP CPU usage display ('c' key)" 161 bool "SMP CPU usage display ('c' key)"
162 default n 162 default y
163 depends on FEATURE_TOP_CPU_GLOBAL_PERCENTS 163 depends on FEATURE_TOP_CPU_GLOBAL_PERCENTS
164 help 164 help
165 Allow 'c' key to switch between individual/cumulative CPU stats 165 Allow 'c' key to switch between individual/cumulative CPU stats
@@ -167,7 +167,7 @@ config FEATURE_TOP_SMP_CPU
167 167
168config FEATURE_TOP_DECIMALS 168config FEATURE_TOP_DECIMALS
169 bool "Show 1/10th of a percent in CPU/mem statistics" 169 bool "Show 1/10th of a percent in CPU/mem statistics"
170 default n 170 default y
171 depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE 171 depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE
172 help 172 help
173 Show 1/10th of a percent in CPU/mem statistics. 173 Show 1/10th of a percent in CPU/mem statistics.
@@ -175,7 +175,7 @@ config FEATURE_TOP_DECIMALS
175 175
176config FEATURE_TOP_SMP_PROCESS 176config FEATURE_TOP_SMP_PROCESS
177 bool "Show CPU process runs on ('j' field)" 177 bool "Show CPU process runs on ('j' field)"
178 default n 178 default y
179 depends on TOP 179 depends on TOP
180 help 180 help
181 Show CPU where process was last found running on. 181 Show CPU where process was last found running on.
@@ -183,21 +183,21 @@ config FEATURE_TOP_SMP_PROCESS
183 183
184config FEATURE_TOPMEM 184config FEATURE_TOPMEM
185 bool "Topmem command ('s' key)" 185 bool "Topmem command ('s' key)"
186 default n 186 default y
187 depends on TOP 187 depends on TOP
188 help 188 help
189 Enable 's' in top (gives lots of memory info). 189 Enable 's' in top (gives lots of memory info).
190 190
191config FEATURE_SHOW_THREADS 191config FEATURE_SHOW_THREADS
192 bool "Support for showing threads in ps/top" 192 bool "Support for showing threads in ps/top"
193 default n 193 default y
194 depends on PS || TOP 194 depends on PS || TOP
195 help 195 help
196 Enables ps -T option and 'h' command in top 196 Enables ps -T option and 'h' command in top
197 197
198config UPTIME 198config UPTIME
199 bool "uptime" 199 bool "uptime"
200 default n 200 default y
201 help 201 help
202 uptime gives a one line display of the current time, how long 202 uptime gives a one line display of the current time, how long
203 the system has been running, how many users are currently logged 203 the system has been running, how many users are currently logged
@@ -205,7 +205,7 @@ config UPTIME
205 205
206config WATCH 206config WATCH
207 bool "watch" 207 bool "watch"
208 default n 208 default y
209 help 209 help
210 watch is used to execute a program periodically, showing 210 watch is used to execute a program periodically, showing
211 output to the screen. 211 output to the screen.
diff --git a/procps/Kbuild b/procps/Kbuild.src
index 8e62fdfa6..8e62fdfa6 100644
--- a/procps/Kbuild
+++ b/procps/Kbuild.src
diff --git a/procps/top.c b/procps/top.c
index e4afafc4c..04dd82633 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -103,11 +103,11 @@ struct globals {
103}; //FIX_ALIASING; - large code growth 103}; //FIX_ALIASING; - large code growth
104enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) }; 104enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
105#define G (*(struct globals*)&bb_common_bufsiz1) 105#define G (*(struct globals*)&bb_common_bufsiz1)
106#define INIT_G() do { \ 106struct BUG_bad_size {
107 struct G_sizecheck { \ 107 char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1];
108 char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \ 108 char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1];
109 }; \ 109};
110} while (0) 110#define INIT_G() do { } while (0)
111#define top (G.top ) 111#define top (G.top )
112#define ntop (G.ntop ) 112#define ntop (G.ntop )
113#define sort_field (G.sort_field ) 113#define sort_field (G.sort_field )
@@ -696,111 +696,70 @@ static int topmem_sort(char *a, char *b)
696 return inverted ? -n : n; 696 return inverted ? -n : n;
697} 697}
698 698
699/* Cut "NNNN" out of " NNNN kb" */
700static char *grab_number(char *str, const char *match, unsigned sz)
701{
702 if (strncmp(str, match, sz) == 0) {
703 str = skip_whitespace(str + sz);
704 (skip_non_whitespace(str))[0] = '\0';
705 return xstrdup(str);
706 }
707 return NULL;
708}
709
710/* display header info (meminfo / loadavg) */ 699/* display header info (meminfo / loadavg) */
711static void display_topmem_header(int scr_width, int *lines_rem_p) 700static void display_topmem_header(int scr_width, int *lines_rem_p)
712{ 701{
713 char linebuf[128]; 702 enum {
703 TOTAL = 0, MFREE, BUF, CACHE,
704 SWAPTOTAL, SWAPFREE, DIRTY,
705 MWRITE, ANON, MAP, SLAB,
706 NUM_FIELDS
707 };
708 static const char match[NUM_FIELDS][12] = {
709 "\x09" "MemTotal:", // TOTAL
710 "\x08" "MemFree:", // MFREE
711 "\x08" "Buffers:", // BUF
712 "\x07" "Cached:", // CACHE
713 "\x0a" "SwapTotal:", // SWAPTOTAL
714 "\x09" "SwapFree:", // SWAPFREE
715 "\x06" "Dirty:", // DIRTY
716 "\x0a" "Writeback:", // MWRITE
717 "\x0a" "AnonPages:", // ANON
718 "\x07" "Mapped:", // MAP
719 "\x05" "Slab:", // SLAB
720 };
721 char meminfo_buf[4 * 1024];
722 const char *Z[NUM_FIELDS];
714 unsigned i; 723 unsigned i;
715 FILE *fp; 724 int sz;
716 union { 725
717 struct { 726 for (i = 0; i < NUM_FIELDS; i++)
718 /* 1 */ char *total; 727 Z[i] = "?";
719 /* 2 */ char *mfree;
720 /* 3 */ char *buf;
721 /* 4 */ char *cache;
722 /* 5 */ char *swaptotal;
723 /* 6 */ char *swapfree;
724 /* 7 */ char *dirty;
725 /* 8 */ char *mwrite;
726 /* 9 */ char *anon;
727 /* 10 */ char *map;
728 /* 11 */ char *slab;
729 } u;
730 char *str[11];
731 } Z;
732#define total Z.u.total
733#define mfree Z.u.mfree
734#define buf Z.u.buf
735#define cache Z.u.cache
736#define swaptotal Z.u.swaptotal
737#define swapfree Z.u.swapfree
738#define dirty Z.u.dirty
739#define mwrite Z.u.mwrite
740#define anon Z.u.anon
741#define map Z.u.map
742#define slab Z.u.slab
743#define str Z.str
744
745 memset(&Z, 0, sizeof(Z));
746 728
747 /* read memory info */ 729 /* read memory info */
748 fp = xfopen_for_read("meminfo"); 730 sz = open_read_close("meminfo", meminfo_buf, sizeof(meminfo_buf) - 1);
749 while (fgets(linebuf, sizeof(linebuf), fp)) { 731 if (sz >= 0) {
750 char *p; 732 char *p = meminfo_buf;
751 733 meminfo_buf[sz] = '\0';
752#define SCAN(match, name) \ 734 /* Note that fields always appear in the match[] order */
753 p = grab_number(linebuf, match, sizeof(match)-1); \ 735 for (i = 0; i < NUM_FIELDS; i++) {
754 if (p) { name = p; continue; } 736 char *found = strstr(p, match[i] + 1);
755 737 if (found) {
756 SCAN("MemTotal:", total); 738 /* Cut "NNNN" out of " NNNN kb" */
757 SCAN("MemFree:", mfree); 739 char *s = skip_whitespace(found + match[i][0]);
758 SCAN("Buffers:", buf); 740 p = skip_non_whitespace(s);
759 SCAN("Cached:", cache); 741 *p++ = '\0';
760 SCAN("SwapTotal:", swaptotal); 742 Z[i] = s;
761 SCAN("SwapFree:", swapfree); 743 }
762 SCAN("Dirty:", dirty); 744 }
763 SCAN("Writeback:", mwrite);
764 SCAN("AnonPages:", anon);
765 SCAN("Mapped:", map);
766 SCAN("Slab:", slab);
767#undef SCAN
768 } 745 }
769 fclose(fp);
770 746
771#define S(s) (s ? s : "0") 747 snprintf(line_buf, LINE_BUF_SIZE,
772 snprintf(linebuf, sizeof(linebuf),
773 "Mem total:%s anon:%s map:%s free:%s", 748 "Mem total:%s anon:%s map:%s free:%s",
774 S(total), S(anon), S(map), S(mfree)); 749 Z[TOTAL], Z[ANON], Z[MAP], Z[MFREE]);
775 printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, linebuf); 750 printf(OPT_BATCH_MODE ? "%.*s\n" : "\033[H\033[J%.*s\n", scr_width, line_buf);
776 751
777 snprintf(linebuf, sizeof(linebuf), 752 snprintf(line_buf, LINE_BUF_SIZE,
778 " slab:%s buf:%s cache:%s dirty:%s write:%s", 753 " slab:%s buf:%s cache:%s dirty:%s write:%s",
779 S(slab), S(buf), S(cache), S(dirty), S(mwrite)); 754 Z[SLAB], Z[BUF], Z[CACHE], Z[DIRTY], Z[MWRITE]);
780 printf("%.*s\n", scr_width, linebuf); 755 printf("%.*s\n", scr_width, line_buf);
781 756
782 snprintf(linebuf, sizeof(linebuf), 757 snprintf(line_buf, LINE_BUF_SIZE,
783 "Swap total:%s free:%s", // TODO: % used? 758 "Swap total:%s free:%s", // TODO: % used?
784 S(swaptotal), S(swapfree)); 759 Z[SWAPTOTAL], Z[SWAPFREE]);
785 printf("%.*s\n", scr_width, linebuf); 760 printf("%.*s\n", scr_width, line_buf);
786 761
787 (*lines_rem_p) -= 3; 762 (*lines_rem_p) -= 3;
788#undef S
789
790 for (i = 0; i < ARRAY_SIZE(str); i++)
791 free(str[i]);
792#undef total
793#undef free
794#undef buf
795#undef cache
796#undef swaptotal
797#undef swapfree
798#undef dirty
799#undef write
800#undef anon
801#undef map
802#undef slab
803#undef str
804} 763}
805 764
806static void ulltoa6_and_space(unsigned long long ul, char buf[6]) 765static void ulltoa6_and_space(unsigned long long ul, char buf[6])