Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/procps/top.c


Ignore:
Timestamp:
Jan 1, 2014, 12:47:38 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.21.1
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mindi-busybox/procps/top.c

    r2725 r3232  
    2020 * Sept 2008: Vineet Gupta <vineet.gupta@arc.com>
    2121 * Added Support for reporting SMP Information
    22  * - CPU where Process was last seen running
     22 * - CPU where process was last seen running
    2323 *   (to see effect of sched_setaffinity() etc)
    24  * - CPU Time Split (idle/IO/wait etc) PER CPU
     24 * - CPU time split (idle/IO/wait etc) per CPU
    2525 *
    2626 * Copyright (c) 1992 Branko Lankester
     
    3131 * Licensed under GPLv2, see file LICENSE in this source tree.
    3232 */
     33/* How to snapshot /proc for debugging top problems:
     34 * for f in /proc/[0-9]*""/stat; do
     35 *         n=${f#/proc/}
     36 *         n=${n%/stat}_stat
     37 *         cp $f $n
     38 * done
     39 * cp /proc/stat /proc/meminfo /proc/loadavg .
     40 * top -bn1 >top.out
     41 *
     42 * ...and how to run top on it on another machine:
     43 * rm -rf proc; mkdir proc
     44 * for f in [0-9]*_stat; do
     45 *         p=${f%_stat}
     46 *         mkdir -p proc/$p
     47 *         cp $f proc/$p/stat
     48 * done
     49 * cp stat meminfo loadavg proc
     50 * chroot . ./top -bn1 >top1.out
     51 */
     52
     53//config:config TOP
     54//config:   bool "top"
     55//config:   default y
     56//config:   help
     57//config:     The top program provides a dynamic real-time view of a running
     58//config:     system.
     59//config:
     60//config:config FEATURE_TOP_CPU_USAGE_PERCENTAGE
     61//config:   bool "Show CPU per-process usage percentage"
     62//config:   default y
     63//config:   depends on TOP
     64//config:   help
     65//config:     Make top display CPU usage for each process.
     66//config:     This adds about 2k.
     67//config:
     68//config:config FEATURE_TOP_CPU_GLOBAL_PERCENTS
     69//config:   bool "Show CPU global usage percentage"
     70//config:   default y
     71//config:   depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE
     72//config:   help
     73//config:     Makes top display "CPU: NN% usr NN% sys..." line.
     74//config:     This adds about 0.5k.
     75//config:
     76//config:config FEATURE_TOP_SMP_CPU
     77//config:   bool "SMP CPU usage display ('c' key)"
     78//config:   default y
     79//config:   depends on FEATURE_TOP_CPU_GLOBAL_PERCENTS
     80//config:   help
     81//config:     Allow 'c' key to switch between individual/cumulative CPU stats
     82//config:     This adds about 0.5k.
     83//config:
     84//config:config FEATURE_TOP_DECIMALS
     85//config:   bool "Show 1/10th of a percent in CPU/mem statistics"
     86//config:   default y
     87//config:   depends on FEATURE_TOP_CPU_USAGE_PERCENTAGE
     88//config:   help
     89//config:     Show 1/10th of a percent in CPU/mem statistics.
     90//config:     This adds about 0.3k.
     91//config:
     92//config:config FEATURE_TOP_SMP_PROCESS
     93//config:   bool "Show CPU process runs on ('j' field)"
     94//config:   default y
     95//config:   depends on TOP
     96//config:   help
     97//config:     Show CPU where process was last found running on.
     98//config:     This is the 'j' field.
     99//config:
     100//config:config FEATURE_TOPMEM
     101//config:   bool "Topmem command ('s' key)"
     102//config:   default y
     103//config:   depends on TOP
     104//config:   help
     105//config:     Enable 's' in top (gives lots of memory info).
    33106
    34107#include "libbb.h"
     
    74147    top_status_t *top;
    75148    int ntop;
     149    smallint inverted;
    76150#if ENABLE_FEATURE_TOPMEM
    77151    smallint sort_field;
    78     smallint inverted;
    79152#endif
    80153#if ENABLE_FEATURE_TOP_SMP_CPU
    81154    smallint smp_cpu_info; /* one/many cpu info lines? */
    82155#endif
     156    unsigned lines;  /* screen height */
    83157#if ENABLE_FEATURE_USE_TERMIOS
    84158    struct termios initial_settings;
     159    int scroll_ofs;
     160#define G_scroll_ofs G.scroll_ofs
     161#else
     162#define G_scroll_ofs 0
    85163#endif
    86164#if !ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
     
    100178    int num_cpus;
    101179#endif
     180#if ENABLE_FEATURE_USE_TERMIOS
     181    char kbd_input[KEYCODE_BUFFER_SIZE];
     182#endif
    102183    char line_buf[80];
    103184}; //FIX_ALIASING; - large code growth
     
    108189    char BUG_line_buf_too_small[LINE_BUF_SIZE > 80 ? 1 : -1];
    109190};
    110 #define INIT_G() do { } while (0)
    111191#define top              (G.top               )
    112192#define ntop             (G.ntop              )
     
    125205#define total_pcpu       (G.total_pcpu        )
    126206#define line_buf         (G.line_buf          )
     207#define INIT_G() do { } while (0)
    127208
    128209enum {
     
    176257        cmp_val = (*sort_function[i])(a, b);
    177258        if (cmp_val != 0)
    178             return cmp_val;
    179     }
    180     return 0;
     259            break;
     260    }
     261    return inverted ? -cmp_val : cmp_val;
    181262}
    182263
     
    520601    /* what info of the processes is shown */
    521602    printf(OPT_BATCH_MODE ? "%.*s" : "\033[7m%.*s\033[0m", scr_width,
    522         "  PID  PPID USER     STAT   VSZ %MEM"
     603        "  PID  PPID USER     STAT   VSZ %VSZ"
    523604        IF_FEATURE_TOP_SMP_PROCESS(" CPU")
    524605        IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE(" %CPU")
     
    538619#endif
    539620    /*
    540      * MEM% = s->vsz/MemTotal
     621     * %VSZ = s->vsz/MemTotal
    541622     */
    542623    pmem_shift = BITS_PER_INT-11;
     
    547628        pmem_shift -= 2;
    548629    }
    549     pmem_half = (1U << pmem_shift) / (ENABLE_FEATURE_TOP_DECIMALS? 20 : 2);
     630    pmem_half = (1U << pmem_shift) / (ENABLE_FEATURE_TOP_DECIMALS ? 20 : 2);
    550631#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
    551632    busy_jifs = cur_jif.busy - prev_jif.busy;
     
    578659        pcpu_shift -= 2;
    579660    }
    580     pcpu_half = (1U << pcpu_shift) / (ENABLE_FEATURE_TOP_DECIMALS? 20 : 2);
     661    pcpu_half = (1U << pcpu_shift) / (ENABLE_FEATURE_TOP_DECIMALS ? 20 : 2);
    581662    /* printf(" pmem_scale=%u pcpu_scale=%u ", pmem_scale, pcpu_scale); */
    582663#endif
     
    584665    /* Ok, all preliminary data is ready, go through the list */
    585666    scr_width += 2; /* account for leading '\n' and trailing NUL */
    586     if (lines_rem > ntop)
    587         lines_rem = ntop;
    588     s = top;
     667    if (lines_rem > ntop - G_scroll_ofs)
     668        lines_rem = ntop - G_scroll_ofs;
     669    s = top + G_scroll_ofs;
    589670    while (--lines_rem >= 0) {
    590671        unsigned col;
     
    598679        else
    599680            sprintf(vsz_str_buf, "%7ld", s->vsz);
    600         /* PID PPID USER STAT VSZ %MEM [%CPU] COMMAND */
     681        /* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
    601682        col = snprintf(line_buf, scr_width,
    602683                "\n" "%5u%6u %-8.8s %s%s" FMT
     
    631712    free(top);
    632713    top = NULL;
    633     ntop = 0;
    634714}
    635715
     
    638718static void reset_term(void)
    639719{
    640     tcsetattr_stdin_TCSANOW(&initial_settings);
     720    if (!OPT_BATCH_MODE)
     721        tcsetattr_stdin_TCSANOW(&initial_settings);
    641722    if (ENABLE_FEATURE_CLEAN_UP) {
    642723        clearmems();
     
    647728}
    648729
    649 static void sig_catcher(int sig UNUSED_PARAM)
     730static void sig_catcher(int sig)
    650731{
    651732    reset_term();
    652     _exit(EXIT_FAILURE);
     733    kill_myself_with_sig(sig);
    653734}
    654735
     
    775856#define HDR_STR "  PID   VSZ VSZRW   RSS (SHR) DIRTY (SHR) STACK"
    776857#define MIN_WIDTH sizeof(HDR_STR)
    777     const topmem_status_t *s = topmem;
     858    const topmem_status_t *s = topmem + G_scroll_ofs;
    778859
    779860    display_topmem_header(scr_width, &lines_rem);
    780861    strcpy(line_buf, HDR_STR " COMMAND");
    781     line_buf[5 + sort_field * 6] = '*';
     862    line_buf[11 + sort_field * 6] = "^_"[inverted];
    782863    printf(OPT_BATCH_MODE ? "%.*s" : "\e[7m%.*s\e[0m", scr_width, line_buf);
    783864    lines_rem--;
    784865
    785     if (lines_rem > ntop)
    786         lines_rem = ntop;
     866    if (lines_rem > ntop - G_scroll_ofs)
     867        lines_rem = ntop - G_scroll_ofs;
    787868    while (--lines_rem >= 0) {
    788869        /* PID VSZ VSZRW RSS (SHR) DIRTY (SHR) COMMAND */
     
    832913        | PSSCAN_SMAPS
    833914        | PSSCAN_COMM,
     915    EXIT_MASK = (unsigned)-1,
    834916};
     917
     918#if ENABLE_FEATURE_USE_TERMIOS
     919static unsigned handle_input(unsigned scan_mask, unsigned interval)
     920{
     921    struct pollfd pfd[1];
     922
     923    if (option_mask32 & OPT_EOF) {
     924        /* EOF on stdin ("top </dev/null") */
     925        sleep(interval);
     926        return scan_mask;
     927    }
     928
     929    pfd[0].fd = 0;
     930    pfd[0].events = POLLIN;
     931
     932    while (1) {
     933        int32_t c;
     934
     935        c = read_key(STDIN_FILENO, G.kbd_input, interval * 1000);
     936        if (c == -1 && errno != EAGAIN) {
     937            /* error/EOF */
     938            option_mask32 |= OPT_EOF;
     939            break;
     940        }
     941        interval = 0;
     942
     943        if (c == initial_settings.c_cc[VINTR])
     944            return EXIT_MASK;
     945        if (c == initial_settings.c_cc[VEOF])
     946            return EXIT_MASK;
     947
     948        if (c == KEYCODE_UP) {
     949            G_scroll_ofs--;
     950            goto normalize_ofs;
     951        }
     952        if (c == KEYCODE_DOWN) {
     953            G_scroll_ofs++;
     954            goto normalize_ofs;
     955        }
     956        if (c == KEYCODE_HOME) {
     957            G_scroll_ofs = 0;
     958            break;
     959        }
     960        if (c == KEYCODE_END) {
     961            G_scroll_ofs = ntop - G.lines / 2;
     962            goto normalize_ofs;
     963        }
     964        if (c == KEYCODE_PAGEUP) {
     965            G_scroll_ofs -= G.lines / 2;
     966            goto normalize_ofs;
     967        }
     968        if (c == KEYCODE_PAGEDOWN) {
     969            G_scroll_ofs += G.lines / 2;
     970 normalize_ofs:
     971            if (G_scroll_ofs >= ntop)
     972                G_scroll_ofs = ntop - 1;
     973            if (G_scroll_ofs < 0)
     974                G_scroll_ofs = 0;
     975            break;
     976        }
     977
     978        c |= 0x20; /* lowercase */
     979        if (c == 'q')
     980            return EXIT_MASK;
     981
     982        if (c == 'n') {
     983            IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
     984            sort_function[0] = pid_sort;
     985            continue;
     986        }
     987        if (c == 'm') {
     988            IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
     989            sort_function[0] = mem_sort;
     990# if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
     991            sort_function[1] = pcpu_sort;
     992            sort_function[2] = time_sort;
     993# endif
     994            continue;
     995        }
     996# if ENABLE_FEATURE_SHOW_THREADS
     997        if (c == 'h'
     998        IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK)
     999        ) {
     1000            scan_mask ^= PSSCAN_TASKS;
     1001            continue;
     1002        }
     1003# endif
     1004# if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
     1005        if (c == 'p') {
     1006            IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
     1007            sort_function[0] = pcpu_sort;
     1008            sort_function[1] = mem_sort;
     1009            sort_function[2] = time_sort;
     1010            continue;
     1011        }
     1012        if (c == 't') {
     1013            IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
     1014            sort_function[0] = time_sort;
     1015            sort_function[1] = mem_sort;
     1016            sort_function[2] = pcpu_sort;
     1017            continue;
     1018        }
     1019#  if ENABLE_FEATURE_TOPMEM
     1020        if (c == 's') {
     1021            scan_mask = TOPMEM_MASK;
     1022            free(prev_hist);
     1023            prev_hist = NULL;
     1024            prev_hist_count = 0;
     1025            sort_field = (sort_field + 1) % NUM_SORT_FIELD;
     1026            continue;
     1027        }
     1028#  endif
     1029        if (c == 'r') {
     1030            inverted ^= 1;
     1031            continue;
     1032        }
     1033#  if ENABLE_FEATURE_TOP_SMP_CPU
     1034        /* procps-2.0.18 uses 'C', 3.2.7 uses '1' */
     1035        if (c == 'c' || c == '1') {
     1036            /* User wants to toggle per cpu <> aggregate */
     1037            if (smp_cpu_info) {
     1038                free(cpu_prev_jif);
     1039                free(cpu_jif);
     1040                cpu_jif = &cur_jif;
     1041                cpu_prev_jif = &prev_jif;
     1042            } else {
     1043                /* Prepare for xrealloc() */
     1044                cpu_jif = cpu_prev_jif = NULL;
     1045            }
     1046            num_cpus = 0;
     1047            smp_cpu_info = !smp_cpu_info;
     1048            get_jiffy_counts();
     1049            continue;
     1050        }
     1051#  endif
     1052# endif
     1053        break; /* unknown key -> force refresh */
     1054    }
     1055
     1056    return scan_mask;
     1057}
     1058#endif
     1059
     1060//usage:#if ENABLE_FEATURE_SHOW_THREADS || ENABLE_FEATURE_TOP_SMP_CPU
     1061//usage:# define IF_SHOW_THREADS_OR_TOP_SMP(...) __VA_ARGS__
     1062//usage:#else
     1063//usage:# define IF_SHOW_THREADS_OR_TOP_SMP(...)
     1064//usage:#endif
     1065//usage:#define top_trivial_usage
     1066//usage:       "[-b] [-nCOUNT] [-dSECONDS]" IF_FEATURE_TOPMEM(" [-m]")
     1067//usage:#define top_full_usage "\n\n"
     1068//usage:       "Provide a view of process activity in real time."
     1069//usage:   "\n""Read the status of all processes from /proc each SECONDS"
     1070//usage:   "\n""and display a screenful of them."
     1071//usage:   "\n""Keys:"
     1072//usage:   "\n""    N/M"
     1073//usage:                IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/P")
     1074//usage:                IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/T")
     1075//usage:           ": " IF_FEATURE_TOPMEM("show CPU usage, ") "sort by pid/mem"
     1076//usage:                IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/cpu")
     1077//usage:                IF_FEATURE_TOP_CPU_USAGE_PERCENTAGE("/time")
     1078//usage:    IF_FEATURE_TOPMEM(
     1079//usage:   "\n""    S: show memory"
     1080//usage:    )
     1081//usage:   "\n""    R: reverse sort"
     1082//usage:    IF_SHOW_THREADS_OR_TOP_SMP(
     1083//usage:   "\n""    "
     1084//usage:                IF_FEATURE_SHOW_THREADS("H: toggle threads")
     1085//usage:                IF_FEATURE_SHOW_THREADS(IF_FEATURE_TOP_SMP_CPU(", "))
     1086//usage:                IF_FEATURE_TOP_SMP_CPU("1: toggle SMP")
     1087//usage:    )
     1088//usage:   "\n""    Q,^C: exit"
     1089//usage:   "\n"
     1090//usage:   "\n""Options:"
     1091//usage:   "\n""    -b  Batch mode"
     1092//usage:   "\n""    -n N    Exit after N iterations"
     1093//usage:   "\n""    -d N    Delay between updates"
     1094//usage:    IF_FEATURE_TOPMEM(
     1095//usage:   "\n""    -m  Same as 's' key"
     1096//usage:    )
     1097
     1098/* Interactive testing:
     1099 * echo sss | ./busybox top
     1100 * - shows memory screen
     1101 * echo sss | ./busybox top -bn1 >mem
     1102 * - saves memory screen - the *whole* list, not first NROWS processes!
     1103 * echo .m.s.s.s.s.s.s.q | ./busybox top -b >z
     1104 * - saves several different screens, and exits
     1105 *
     1106 * TODO: -i STRING param as a better alternative?
     1107 */
    8351108
    8361109int top_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    8381111{
    8391112    int iterations;
    840     unsigned lines, col;
    841     int lines_rem;
     1113    unsigned col;
    8421114    unsigned interval;
    8431115    char *str_interval, *str_iterations;
     
    8451117#if ENABLE_FEATURE_USE_TERMIOS
    8461118    struct termios new_settings;
    847     struct pollfd pfd[1];
    848     unsigned char c;
    849 
    850     pfd[0].fd = 0;
    851     pfd[0].events = POLLIN;
    8521119#endif
    8531120
     
    8861153    /* change to /proc */
    8871154    xchdir("/proc");
    888 #if ENABLE_FEATURE_USE_TERMIOS
    889     tcgetattr(0, (void *) &initial_settings);
    890     memcpy(&new_settings, &initial_settings, sizeof(new_settings));
    891     /* unbuffered input, turn off echo */
    892     new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
    893 
    894     bb_signals(BB_FATAL_SIGS, sig_catcher);
    895     tcsetattr_stdin_TCSANOW(&new_settings);
    896 #endif
    8971155
    8981156#if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
     
    9041162#endif
    9051163
    906     while (1) {
     1164    if (OPT_BATCH_MODE) {
     1165        option_mask32 |= OPT_EOF;
     1166    }
     1167#if ENABLE_FEATURE_USE_TERMIOS
     1168    else {
     1169        tcgetattr(0, (void *) &initial_settings);
     1170        memcpy(&new_settings, &initial_settings, sizeof(new_settings));
     1171        /* unbuffered input, turn off echo */
     1172        new_settings.c_lflag &= ~(ISIG | ICANON | ECHO | ECHONL);
     1173        tcsetattr_stdin_TCSANOW(&new_settings);
     1174    }
     1175
     1176    bb_signals(BB_FATAL_SIGS, sig_catcher);
     1177
     1178    /* Eat initial input, if any */
     1179    scan_mask = handle_input(scan_mask, 0);
     1180#endif
     1181
     1182    while (scan_mask != EXIT_MASK) {
    9071183        procps_status_t *p = NULL;
    9081184
    909         lines = 24; /* default */
    910         col = 79;
     1185        if (OPT_BATCH_MODE) {
     1186            G.lines = INT_MAX;
     1187            col = LINE_BUF_SIZE - 2; /* +2 bytes for '\n', NUL */
     1188        } else {
     1189            G.lines = 24; /* default */
     1190            col = 79;
    9111191#if ENABLE_FEATURE_USE_TERMIOS
    912         /* We output to stdout, we need size of stdout (not stdin)! */
    913         get_terminal_width_height(STDOUT_FILENO, &col, &lines);
    914         if (lines < 5 || col < 10) {
    915             sleep(interval);
    916             continue;
    917         }
    918 #endif
    919         if (col > LINE_BUF_SIZE-2) /* +2 bytes for '\n', NUL, */
    920             col = LINE_BUF_SIZE-2;
     1192            /* We output to stdout, we need size of stdout (not stdin)! */
     1193            get_terminal_width_height(STDOUT_FILENO, &col, &G.lines);
     1194            if (G.lines < 5 || col < 10) {
     1195                sleep(interval);
     1196                continue;
     1197            }
     1198#endif
     1199            if (col > LINE_BUF_SIZE - 2)
     1200                col = LINE_BUF_SIZE - 2;
     1201        }
    9211202
    9221203        /* read process IDs & status for all the processes */
     1204        ntop = 0;
    9231205        while ((p = procps_scan(p, scan_mask)) != NULL) {
    9241206            int n;
     
    9861268        }
    9871269#endif
    988         lines_rem = lines;
    989         if (OPT_BATCH_MODE) {
    990             lines_rem = INT_MAX;
    991         }
    9921270        if (scan_mask != TOPMEM_MASK)
    993             display_process_list(lines_rem, col);
     1271            display_process_list(G.lines, col);
    9941272#if ENABLE_FEATURE_TOPMEM
    9951273        else
    996             display_topmem_process_list(lines_rem, col);
     1274            display_topmem_process_list(G.lines, col);
    9971275#endif
    9981276        clearmems();
     
    10021280        sleep(interval);
    10031281#else
    1004         if (option_mask32 & (OPT_b|OPT_EOF))
    1005              /* batch mode, or EOF on stdin ("top </dev/null") */
    1006             sleep(interval);
    1007         else if (safe_poll(pfd, 1, interval * 1000) > 0) {
    1008             if (safe_read(STDIN_FILENO, &c, 1) != 1) { /* error/EOF? */
    1009                 option_mask32 |= OPT_EOF;
    1010                 continue;
    1011             }
    1012             if (c == initial_settings.c_cc[VINTR])
    1013                 break;
    1014             c |= 0x20; /* lowercase */
    1015             if (c == 'q')
    1016                 break;
    1017             if (c == 'n') {
    1018                 IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
    1019                 sort_function[0] = pid_sort;
    1020             }
    1021             if (c == 'm') {
    1022                 IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
    1023                 sort_function[0] = mem_sort;
    1024 # if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
    1025                 sort_function[1] = pcpu_sort;
    1026                 sort_function[2] = time_sort;
    1027 # endif
    1028             }
    1029 # if ENABLE_FEATURE_SHOW_THREADS
    1030             if (c == 'h'
    1031              IF_FEATURE_TOPMEM(&& scan_mask != TOPMEM_MASK)
    1032             ) {
    1033                 scan_mask ^= PSSCAN_TASKS;
    1034             }
    1035 # endif
    1036 # if ENABLE_FEATURE_TOP_CPU_USAGE_PERCENTAGE
    1037             if (c == 'p') {
    1038                 IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
    1039                 sort_function[0] = pcpu_sort;
    1040                 sort_function[1] = mem_sort;
    1041                 sort_function[2] = time_sort;
    1042             }
    1043             if (c == 't') {
    1044                 IF_FEATURE_TOPMEM(scan_mask = TOP_MASK;)
    1045                 sort_function[0] = time_sort;
    1046                 sort_function[1] = mem_sort;
    1047                 sort_function[2] = pcpu_sort;
    1048             }
    1049 #  if ENABLE_FEATURE_TOPMEM
    1050             if (c == 's') {
    1051                 scan_mask = TOPMEM_MASK;
    1052                 free(prev_hist);
    1053                 prev_hist = NULL;
    1054                 prev_hist_count = 0;
    1055                 sort_field = (sort_field + 1) % NUM_SORT_FIELD;
    1056             }
    1057             if (c == 'r')
    1058                 inverted ^= 1;
    1059 #  endif
    1060 #  if ENABLE_FEATURE_TOP_SMP_CPU
    1061             /* procps-2.0.18 uses 'C', 3.2.7 uses '1' */
    1062             if (c == 'c' || c == '1') {
    1063                 /* User wants to toggle per cpu <> aggregate */
    1064                 if (smp_cpu_info) {
    1065                     free(cpu_prev_jif);
    1066                     free(cpu_jif);
    1067                     cpu_jif = &cur_jif;
    1068                     cpu_prev_jif = &prev_jif;
    1069                 } else {
    1070                     /* Prepare for xrealloc() */
    1071                     cpu_jif = cpu_prev_jif = NULL;
    1072                 }
    1073                 num_cpus = 0;
    1074                 smp_cpu_info = !smp_cpu_info;
    1075                 get_jiffy_counts();
    1076             }
    1077 #  endif
    1078 # endif
    1079         }
     1282        scan_mask = handle_input(scan_mask, interval);
    10801283#endif /* FEATURE_USE_TERMIOS */
    1081     } /* end of "while (1)" */
     1284    } /* end of "while (not Q)" */
    10821285
    10831286    bb_putchar('\n');
Note: See TracChangeset for help on using the changeset viewer.