aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 12:55:19 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2022-05-10 12:56:28 +0200
commit294881d2e9ab014f918fba63c01a629906508515 (patch)
tree19a269d16d53e888536200c5bf0c0712ef9f6568
parent67fd6be0bb925839f4e6564dba741f9889b2fac8 (diff)
downloadbusybox-w32-294881d2e9ab014f918fba63c01a629906508515.tar.gz
busybox-w32-294881d2e9ab014f918fba63c01a629906508515.tar.bz2
busybox-w32-294881d2e9ab014f918fba63c01a629906508515.zip
top: fix display of large PID/PPID
function old new delta display_process_list 1077 1191 +114 .rodata 104803 104807 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 118/0) Total: 118 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--procps/top.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/procps/top.c b/procps/top.c
index 804d6f258..15222f570 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -608,6 +608,8 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
608 BITS_PER_INT = sizeof(int) * 8 608 BITS_PER_INT = sizeof(int) * 8
609 }; 609 };
610 610
611 char ppubuf[sizeof(int)*3 * 2 + 12];
612 int n;
611 top_status_t *s; 613 top_status_t *s;
612 unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */ 614 unsigned long total_memory = display_header(scr_width, &lines_rem); /* or use total_vsz? */
613 /* xxx_shift and xxx_scale variables allow us to replace 615 /* xxx_shift and xxx_scale variables allow us to replace
@@ -699,12 +701,36 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
699 701
700 smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); 702 smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy");
701 /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ 703 /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
704 n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid));
705 if (n != 6+6+8) {
706 /* Format PID PPID USER part into 6+6+8 chars:
707 * shrink PID/PPID if possible, then truncate USER
708 */
709 char *pp, *p = ppubuf;
710 if (*p == ' ') {
711 do
712 p++, n--;
713 while (n != 6+6+8 && *p == ' ');
714 overlapping_strcpy(ppubuf, p); /* shrink PID */
715 if (n == 6+6+8)
716 goto shortened;
717 }
718 pp = p = skip_non_whitespace(ppubuf) + 1;
719 if (*p == ' ') {
720 do
721 p++, n--;
722 while (n != 6+6+8 && *p == ' ');
723 overlapping_strcpy(pp, p); /* shrink PPID */
724 }
725 ppubuf[6+6+8] = '\0'; /* truncate USER */
726 }
727 shortened:
702 col = snprintf(line_buf, scr_width, 728 col = snprintf(line_buf, scr_width,
703 "\n" "%5u%6u %-8.8s %s %.5s" FMT 729 "\n" "%s %s %.5s" FMT
704 IF_FEATURE_TOP_SMP_PROCESS(" %3d") 730 IF_FEATURE_TOP_SMP_PROCESS(" %3d")
705 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) 731 IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT)
706 " ", 732 " ",
707 s->pid, s->ppid, get_cached_username(s->uid), 733 ppubuf,
708 s->state, vsz_str_buf, 734 s->state, vsz_str_buf,
709 SHOW_STAT(pmem) 735 SHOW_STAT(pmem)
710 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) 736 IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu)