diff options
Diffstat (limited to 'procps/top.c')
-rw-r--r-- | procps/top.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/procps/top.c b/procps/top.c index c02a959e0..abc7a4363 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -448,7 +448,7 @@ static void display_status(int count, int scr_width) | |||
448 | #endif | 448 | #endif |
449 | 449 | ||
450 | if (s->vsz >= 100*1024) | 450 | if (s->vsz >= 100*1024) |
451 | sprintf(vsz_str_buf, "%6ldM", s->vsz/1024); | 451 | sprintf(vsz_str_buf, "%6ldm", s->vsz/1024); |
452 | else | 452 | else |
453 | sprintf(vsz_str_buf, "%7ld", s->vsz); | 453 | sprintf(vsz_str_buf, "%7ld", s->vsz); |
454 | // PID PPID USER STAT VSZ %MEM [%CPU] COMMAND | 454 | // PID PPID USER STAT VSZ %MEM [%CPU] COMMAND |
@@ -519,23 +519,29 @@ int top_main(int argc, char **argv); | |||
519 | int top_main(int argc, char **argv) | 519 | int top_main(int argc, char **argv) |
520 | { | 520 | { |
521 | int count, lines, col; | 521 | int count, lines, col; |
522 | unsigned interval = 5; /* default update rate is 5 seconds */ | 522 | unsigned interval; |
523 | unsigned iterations = UINT_MAX; /* 2^32 iterations by default :) */ | 523 | int iterations = -1; /* infinite */ |
524 | char *sinterval, *siterations; | 524 | char *sinterval, *siterations; |
525 | #if ENABLE_FEATURE_USE_TERMIOS | 525 | #if ENABLE_FEATURE_USE_TERMIOS |
526 | struct termios new_settings; | 526 | struct termios new_settings; |
527 | struct timeval tv; | 527 | struct pollfd pfd[1]; |
528 | fd_set readfds; | ||
529 | unsigned char c; | 528 | unsigned char c; |
529 | |||
530 | pfd[0].fd = 0; | ||
531 | pfd[0].events = POLLIN; | ||
530 | #endif /* FEATURE_USE_TERMIOS */ | 532 | #endif /* FEATURE_USE_TERMIOS */ |
531 | 533 | ||
532 | interval = 5; | 534 | interval = 5; /* default update rate is 5 seconds */ |
533 | 535 | ||
534 | /* do normal option parsing */ | 536 | /* do normal option parsing */ |
535 | opt_complementary = "-"; | 537 | opt_complementary = "-"; |
536 | getopt32(argv, "d:n:b", &sinterval, &siterations); | 538 | getopt32(argv, "d:n:b", &sinterval, &siterations); |
537 | if (option_mask32 & 0x1) interval = xatou(sinterval); // -d | 539 | if (option_mask32 & 0x1) { |
538 | if (option_mask32 & 0x2) iterations = xatou(siterations); // -n | 540 | /* Need to limit it to not overflow poll timeout */ |
541 | interval = xatou16(sinterval); // -d | ||
542 | } | ||
543 | if (option_mask32 & 0x2) | ||
544 | iterations = xatoi_u(siterations); // -n | ||
539 | //if (option_mask32 & 0x4) // -b | 545 | //if (option_mask32 & 0x4) // -b |
540 | 546 | ||
541 | /* change to /proc */ | 547 | /* change to /proc */ |
@@ -584,9 +590,8 @@ int top_main(int argc, char **argv) | |||
584 | | PSSCAN_UTIME | 590 | | PSSCAN_UTIME |
585 | | PSSCAN_STATE | 591 | | PSSCAN_STATE |
586 | | PSSCAN_COMM | 592 | | PSSCAN_COMM |
587 | | PSSCAN_SID | ||
588 | | PSSCAN_UIDGID | 593 | | PSSCAN_UIDGID |
589 | ))) { | 594 | )) != NULL) { |
590 | int n = ntop; | 595 | int n = ntop; |
591 | top = xrealloc(top, (++ntop) * sizeof(*top)); | 596 | top = xrealloc(top, (++ntop) * sizeof(*top)); |
592 | top[n].pid = p->pid; | 597 | top[n].pid = p->pid; |
@@ -622,15 +627,9 @@ int top_main(int argc, char **argv) | |||
622 | /* show status for each of the processes */ | 627 | /* show status for each of the processes */ |
623 | display_status(count, col); | 628 | display_status(count, col); |
624 | #if ENABLE_FEATURE_USE_TERMIOS | 629 | #if ENABLE_FEATURE_USE_TERMIOS |
625 | tv.tv_sec = interval; | 630 | if (poll(pfd, 1, interval * 1000) != 0) { |
626 | tv.tv_usec = 0; | 631 | if (read(0, &c, 1) != 1) /* signal */ |
627 | FD_ZERO(&readfds); | 632 | break; |
628 | FD_SET(0, &readfds); | ||
629 | select(1, &readfds, NULL, NULL, &tv); | ||
630 | if (FD_ISSET(0, &readfds)) { | ||
631 | if (read(0, &c, 1) <= 0) { /* signal */ | ||
632 | return EXIT_FAILURE; | ||
633 | } | ||
634 | if (c == 'q' || c == initial_settings.c_cc[VINTR]) | 633 | if (c == 'q' || c == initial_settings.c_cc[VINTR]) |
635 | break; | 634 | break; |
636 | if (c == 'M') { | 635 | if (c == 'M') { |
@@ -662,7 +661,7 @@ int top_main(int argc, char **argv) | |||
662 | #endif | 661 | #endif |
663 | } | 662 | } |
664 | } | 663 | } |
665 | if (!--iterations) | 664 | if (iterations >= 0 && !--iterations) |
666 | break; | 665 | break; |
667 | #else | 666 | #else |
668 | sleep(interval); | 667 | sleep(interval); |