aboutsummaryrefslogtreecommitdiff
path: root/procps/top.c
diff options
context:
space:
mode:
Diffstat (limited to 'procps/top.c')
-rw-r--r--procps/top.c42
1 files changed, 20 insertions, 22 deletions
diff --git a/procps/top.c b/procps/top.c
index 71207bac1..ff2fddeea 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -56,6 +56,14 @@
56//config: The top program provides a dynamic real-time view of a running 56//config: The top program provides a dynamic real-time view of a running
57//config: system. 57//config: system.
58//config: 58//config:
59//config:config FEATURE_TOP_INTERACTIVE
60//config: bool "Accept keyboard commands"
61//config: default y
62//config: depends on TOP
63//config: help
64//config: Without this, top will only refresh display every 5 seconds.
65//config: No keyboard commands will work, only ^C to terminate.
66//config:
59//config:config FEATURE_TOP_CPU_USAGE_PERCENTAGE 67//config:config FEATURE_TOP_CPU_USAGE_PERCENTAGE
60//config: bool "Show CPU per-process usage percentage" 68//config: bool "Show CPU per-process usage percentage"
61//config: default y 69//config: default y
@@ -158,7 +166,7 @@ struct globals {
158 smallint smp_cpu_info; /* one/many cpu info lines? */ 166 smallint smp_cpu_info; /* one/many cpu info lines? */
159#endif 167#endif
160 unsigned lines; /* screen height */ 168 unsigned lines; /* screen height */
161#if ENABLE_FEATURE_USE_TERMIOS 169#if ENABLE_FEATURE_TOP_INTERACTIVE
162 struct termios initial_settings; 170 struct termios initial_settings;
163 int scroll_ofs; 171 int scroll_ofs;
164#define G_scroll_ofs G.scroll_ofs 172#define G_scroll_ofs G.scroll_ofs
@@ -181,7 +189,7 @@ struct globals {
181 jiffy_counts_t *cpu_jif, *cpu_prev_jif; 189 jiffy_counts_t *cpu_jif, *cpu_prev_jif;
182 int num_cpus; 190 int num_cpus;
183#endif 191#endif
184#if ENABLE_FEATURE_USE_TERMIOS 192#if ENABLE_FEATURE_TOP_INTERACTIVE
185 char kbd_input[KEYCODE_BUFFER_SIZE]; 193 char kbd_input[KEYCODE_BUFFER_SIZE];
186#endif 194#endif
187 char line_buf[80]; 195 char line_buf[80];
@@ -220,7 +228,7 @@ enum {
220#define OPT_BATCH_MODE (option_mask32 & OPT_b) 228#define OPT_BATCH_MODE (option_mask32 & OPT_b)
221 229
222 230
223#if ENABLE_FEATURE_USE_TERMIOS 231#if ENABLE_FEATURE_TOP_INTERACTIVE
224static int pid_sort(top_status_t *P, top_status_t *Q) 232static int pid_sort(top_status_t *P, top_status_t *Q)
225{ 233{
226 /* Buggy wrt pids with high bit set */ 234 /* Buggy wrt pids with high bit set */
@@ -725,8 +733,7 @@ static void clearmems(void)
725 top = NULL; 733 top = NULL;
726} 734}
727 735
728#if ENABLE_FEATURE_USE_TERMIOS 736#if ENABLE_FEATURE_TOP_INTERACTIVE
729
730static void reset_term(void) 737static void reset_term(void)
731{ 738{
732 if (!OPT_BATCH_MODE) 739 if (!OPT_BATCH_MODE)
@@ -738,8 +745,7 @@ static void sig_catcher(int sig)
738 reset_term(); 745 reset_term();
739 kill_myself_with_sig(sig); 746 kill_myself_with_sig(sig);
740} 747}
741 748#endif /* FEATURE_TOP_INTERACTIVE */
742#endif /* FEATURE_USE_TERMIOS */
743 749
744/* 750/*
745 * TOPMEM support 751 * TOPMEM support
@@ -894,7 +900,7 @@ enum {
894 EXIT_MASK = (unsigned)-1, 900 EXIT_MASK = (unsigned)-1,
895}; 901};
896 902
897#if ENABLE_FEATURE_USE_TERMIOS 903#if ENABLE_FEATURE_TOP_INTERACTIVE
898static unsigned handle_input(unsigned scan_mask, unsigned interval) 904static unsigned handle_input(unsigned scan_mask, unsigned interval)
899{ 905{
900 if (option_mask32 & OPT_EOF) { 906 if (option_mask32 & OPT_EOF) {
@@ -1043,7 +1049,7 @@ static unsigned handle_input(unsigned scan_mask, unsigned interval)
1043//usage: "\n""Read the status of all processes from /proc each SECONDS" 1049//usage: "\n""Read the status of all processes from /proc each SECONDS"
1044//usage: "\n""and display a screenful of them." 1050//usage: "\n""and display a screenful of them."
1045//usage: "\n" 1051//usage: "\n"
1046//usage: IF_FEATURE_USE_TERMIOS( 1052//usage: IF_FEATURE_TOP_INTERACTIVE(
1047//usage: "Keys:" 1053//usage: "Keys:"
1048//usage: "\n"" N/M" 1054//usage: "\n"" N/M"
1049//usage: IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/P") 1055//usage: IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/P")
@@ -1091,9 +1097,6 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1091 unsigned interval; 1097 unsigned interval;
1092 char *str_interval, *str_iterations; 1098 char *str_interval, *str_iterations;
1093 unsigned scan_mask = TOP_MASK; 1099 unsigned scan_mask = TOP_MASK;
1094#if ENABLE_FEATURE_USE_TERMIOS
1095 struct termios new_settings;
1096#endif
1097 1100
1098 INIT_G(); 1101 INIT_G();
1099 1102
@@ -1141,13 +1144,10 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1141 if (OPT_BATCH_MODE) { 1144 if (OPT_BATCH_MODE) {
1142 option_mask32 |= OPT_EOF; 1145 option_mask32 |= OPT_EOF;
1143 } 1146 }
1144#if ENABLE_FEATURE_USE_TERMIOS 1147#if ENABLE_FEATURE_TOP_INTERACTIVE
1145 else { 1148 else {
1146 tcgetattr(0, (void *) &initial_settings); 1149 /* Turn on unbuffered input; turn off echoing, ^C ^Z etc */
1147 memcpy(&new_settings, &initial_settings, sizeof(new_settings)); 1150 set_termios_to_raw(STDIN_FILENO, &initial_settings, TERMIOS_CLEAR_ISIG);
1148 /* unbuffered input, turn off echo */
1149 new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
1150 tcsetattr_stdin_TCSANOW(&new_settings);
1151 } 1151 }
1152 1152
1153 bb_signals(BB_FATAL_SIGS, sig_catcher); 1153 bb_signals(BB_FATAL_SIGS, sig_catcher);
@@ -1165,14 +1165,12 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1165 } else { 1165 } else {
1166 G.lines = 24; /* default */ 1166 G.lines = 24; /* default */
1167 col = 79; 1167 col = 79;
1168#if ENABLE_FEATURE_USE_TERMIOS
1169 /* We output to stdout, we need size of stdout (not stdin)! */ 1168 /* We output to stdout, we need size of stdout (not stdin)! */
1170 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines); 1169 get_terminal_width_height(STDOUT_FILENO, &col, &G.lines);
1171 if (G.lines < 5 || col < 10) { 1170 if (G.lines < 5 || col < 10) {
1172 sleep(interval); 1171 sleep(interval);
1173 continue; 1172 continue;
1174 } 1173 }
1175#endif
1176 if (col > LINE_BUF_SIZE - 2) 1174 if (col > LINE_BUF_SIZE - 2)
1177 col = LINE_BUF_SIZE - 2; 1175 col = LINE_BUF_SIZE - 2;
1178 } 1176 }
@@ -1247,7 +1245,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1247 clearmems(); 1245 clearmems();
1248 if (iterations >= 0 && !--iterations) 1246 if (iterations >= 0 && !--iterations)
1249 break; 1247 break;
1250#if !ENABLE_FEATURE_USE_TERMIOS 1248#if !ENABLE_FEATURE_TOP_INTERACTIVE
1251 sleep(interval); 1249 sleep(interval);
1252#else 1250#else
1253 scan_mask = handle_input(scan_mask, interval); 1251 scan_mask = handle_input(scan_mask, interval);
@@ -1255,7 +1253,7 @@ int top_main(int argc UNUSED_PARAM, char **argv)
1255 } /* end of "while (not Q)" */ 1253 } /* end of "while (not Q)" */
1256 1254
1257 bb_putchar('\n'); 1255 bb_putchar('\n');
1258#if ENABLE_FEATURE_USE_TERMIOS 1256#if ENABLE_FEATURE_TOP_INTERACTIVE
1259 reset_term(); 1257 reset_term();
1260#endif 1258#endif
1261 if (ENABLE_FEATURE_CLEAN_UP) { 1259 if (ENABLE_FEATURE_CLEAN_UP) {