summaryrefslogtreecommitdiff
path: root/busybox/procps
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-08-13 01:22:03 +0000
committerRob Landley <rob@landley.net>2005-08-13 01:22:03 +0000
commit0be69b16932c5adafb0c031515d9d4d9cb982aae (patch)
tree4b25ce6936f308a26c99452186ee533a21fa68a5 /busybox/procps
parentc7cba1ae3bacb11de6a11df8c2fc98a69e423d7d (diff)
downloadbusybox-w32-0be69b16932c5adafb0c031515d9d4d9cb982aae.tar.gz
busybox-w32-0be69b16932c5adafb0c031515d9d4d9cb982aae.tar.bz2
busybox-w32-0be69b16932c5adafb0c031515d9d4d9cb982aae.zip
More backports:
10957 start-stop-daemon -q 10981, 10982, 10994, 10996, 10997: dumpkmap cleanup 10983: top tweak 11000 traceroute
Diffstat (limited to 'busybox/procps')
-rw-r--r--busybox/procps/top.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/busybox/procps/top.c b/busybox/procps/top.c
index 5963c3554..6a129efcf 100644
--- a/busybox/procps/top.c
+++ b/busybox/procps/top.c
@@ -52,11 +52,12 @@ typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q);
52static procps_status_t *top; /* Hehe */ 52static procps_status_t *top; /* Hehe */
53static int ntop; 53static int ntop;
54 54
55 55#ifdef CONFIG_FEATURE_USE_TERMIOS
56static int pid_sort (procps_status_t *P, procps_status_t *Q) 56static int pid_sort (procps_status_t *P, procps_status_t *Q)
57{ 57{
58 return (Q->pid - P->pid); 58 return (Q->pid - P->pid);
59} 59}
60#endif
60 61
61static int mem_sort (procps_status_t *P, procps_status_t *Q) 62static int mem_sort (procps_status_t *P, procps_status_t *Q)
62{ 63{
@@ -410,7 +411,7 @@ static void clearmems(void)
410 ntop = 0; 411 ntop = 0;
411} 412}
412 413
413#if defined CONFIG_FEATURE_USE_TERMIOS 414#ifdef CONFIG_FEATURE_USE_TERMIOS
414#include <termios.h> 415#include <termios.h>
415#include <sys/time.h> 416#include <sys/time.h>
416#include <signal.h> 417#include <signal.h>
@@ -439,7 +440,7 @@ static void sig_catcher (int sig)
439int top_main(int argc, char **argv) 440int top_main(int argc, char **argv)
440{ 441{
441 int opt, interval, lines, col; 442 int opt, interval, lines, col;
442#if defined CONFIG_FEATURE_USE_TERMIOS 443#ifdef CONFIG_FEATURE_USE_TERMIOS
443 struct termios new_settings; 444 struct termios new_settings;
444 struct timeval tv; 445 struct timeval tv;
445 fd_set readfds; 446 fd_set readfds;
@@ -473,7 +474,7 @@ int top_main(int argc, char **argv)
473 if (chdir("/proc") < 0) { 474 if (chdir("/proc") < 0) {
474 bb_perror_msg_and_die("chdir('/proc')"); 475 bb_perror_msg_and_die("chdir('/proc')");
475 } 476 }
476#if defined CONFIG_FEATURE_USE_TERMIOS 477#ifdef CONFIG_FEATURE_USE_TERMIOS
477 tcgetattr(0, (void *) &initial_settings); 478 tcgetattr(0, (void *) &initial_settings);
478 memcpy(&new_settings, &initial_settings, sizeof(struct termios)); 479 memcpy(&new_settings, &initial_settings, sizeof(struct termios));
479 new_settings.c_lflag &= ~(ISIG | ICANON); /* unbuffered input */ 480 new_settings.c_lflag &= ~(ISIG | ICANON); /* unbuffered input */
@@ -499,13 +500,15 @@ int top_main(int argc, char **argv)
499#endif 500#endif
500 } 501 }
501#endif /* CONFIG_FEATURE_USE_TERMIOS */ 502#endif /* CONFIG_FEATURE_USE_TERMIOS */
503
502#ifdef FEATURE_CPU_USAGE_PERCENTAGE 504#ifdef FEATURE_CPU_USAGE_PERCENTAGE
503 sort_function[0] = pcpu_sort; 505 sort_function[0] = pcpu_sort;
504 sort_function[1] = mem_sort; 506 sort_function[1] = mem_sort;
505 sort_function[2] = time_sort; 507 sort_function[2] = time_sort;
506#else 508#else
507 sort_function = mem_sort; 509 sort_function = mem_sort;
508#endif 510#endif /* FEATURE_CPU_USAGE_PERCENTAGE */
511
509 while (1) { 512 while (1) {
510 /* read process IDs & status for all the processes */ 513 /* read process IDs & status for all the processes */
511 procps_status_t * p; 514 procps_status_t * p;
@@ -534,14 +537,14 @@ int top_main(int argc, char **argv)
534 do_stats(); 537 do_stats();
535#else 538#else
536 qsort(top, ntop, sizeof(procps_status_t), (void*)sort_function); 539 qsort(top, ntop, sizeof(procps_status_t), (void*)sort_function);
537#endif 540#endif /* FEATURE_CPU_USAGE_PERCENTAGE */
538 opt = lines; 541 opt = lines;
539 if (opt > ntop) { 542 if (opt > ntop) {
540 opt = ntop; 543 opt = ntop;
541 } 544 }
542 /* show status for each of the processes */ 545 /* show status for each of the processes */
543 display_status(opt, col); 546 display_status(opt, col);
544#if defined CONFIG_FEATURE_USE_TERMIOS 547#ifdef CONFIG_FEATURE_USE_TERMIOS
545 tv.tv_sec = interval; 548 tv.tv_sec = interval;
546 tv.tv_usec = 0; 549 tv.tv_usec = 0;
547 FD_ZERO (&readfds); 550 FD_ZERO (&readfds);
@@ -549,8 +552,8 @@ int top_main(int argc, char **argv)
549 select (1, &readfds, NULL, NULL, &tv); 552 select (1, &readfds, NULL, NULL, &tv);
550 if (FD_ISSET (0, &readfds)) { 553 if (FD_ISSET (0, &readfds)) {
551 if (read (0, &c, 1) <= 0) { /* signal */ 554 if (read (0, &c, 1) <= 0) { /* signal */
552 return EXIT_FAILURE; 555 return EXIT_FAILURE;
553 } 556 }
554 if(c == 'q' || c == initial_settings.c_cc[VINTR]) 557 if(c == 'q' || c == initial_settings.c_cc[VINTR])
555 return EXIT_SUCCESS; 558 return EXIT_SUCCESS;
556 if(c == 'M') { 559 if(c == 'M') {
@@ -584,7 +587,7 @@ int top_main(int argc, char **argv)
584 } 587 }
585#else 588#else
586 sleep(interval); 589 sleep(interval);
587#endif /* CONFIG_FEATURE_USE_TERMIOS */ 590#endif /* CONFIG_FEATURE_USE_TERMIOS */
588 clearmems(); 591 clearmems();
589 } 592 }
590 593