diff options
Diffstat (limited to 'procps')
-rw-r--r-- | procps/top.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/procps/top.c b/procps/top.c index 804d6f258..744f20e9b 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -689,6 +689,9 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
689 | lines_rem = ntop - G_scroll_ofs; | 689 | lines_rem = ntop - G_scroll_ofs; |
690 | s = top + G_scroll_ofs; | 690 | s = top + G_scroll_ofs; |
691 | while (--lines_rem >= 0) { | 691 | while (--lines_rem >= 0) { |
692 | int n; | ||
693 | char *ppu; | ||
694 | char ppubuf[sizeof(int)*3 * 2 + 12]; | ||
692 | char vsz_str_buf[8]; | 695 | char vsz_str_buf[8]; |
693 | unsigned col; | 696 | unsigned col; |
694 | 697 | ||
@@ -699,12 +702,36 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width) | |||
699 | 702 | ||
700 | smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); | 703 | smart_ulltoa5(s->vsz, vsz_str_buf, " mgtpezy"); |
701 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ | 704 | /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */ |
705 | n = sprintf(ppubuf, "%5u %5u %-8.8s", s->pid, s->ppid, get_cached_username(s->uid)); | ||
706 | ppu = ppubuf; | ||
707 | if (n != 6+6+8) { | ||
708 | /* Format PID PPID USER part into 6+6+8 chars: | ||
709 | * shrink PID/PPID if possible, then truncate USER | ||
710 | */ | ||
711 | char *p, *pp; | ||
712 | if (*ppu == ' ') { | ||
713 | do { | ||
714 | ppu++, n--; | ||
715 | if (n == 6+6+8) | ||
716 | goto shortened; | ||
717 | } while (*ppu == ' '); | ||
718 | } | ||
719 | pp = p = skip_non_whitespace(ppu) + 1; | ||
720 | if (*p == ' ') { | ||
721 | do | ||
722 | p++, n--; | ||
723 | while (n != 6+6+8 && *p == ' '); | ||
724 | overlapping_strcpy(pp, p); /* shrink PPID */ | ||
725 | } | ||
726 | ppu[6+6+8] = '\0'; /* truncate USER */ | ||
727 | } | ||
728 | shortened: | ||
702 | col = snprintf(line_buf, scr_width, | 729 | col = snprintf(line_buf, scr_width, |
703 | "\n" "%5u%6u %-8.8s %s %.5s" FMT | 730 | "\n" "%s %s %.5s" FMT |
704 | IF_FEATURE_TOP_SMP_PROCESS(" %3d") | 731 | IF_FEATURE_TOP_SMP_PROCESS(" %3d") |
705 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) | 732 | IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(FMT) |
706 | " ", | 733 | " ", |
707 | s->pid, s->ppid, get_cached_username(s->uid), | 734 | ppu, |
708 | s->state, vsz_str_buf, | 735 | s->state, vsz_str_buf, |
709 | SHOW_STAT(pmem) | 736 | SHOW_STAT(pmem) |
710 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) | 737 | IF_FEATURE_TOP_SMP_PROCESS(, s->last_seen_on_cpu) |