TOP(1) | General Commands Manual | TOP(1) |
top - display and update information about the top cpu processes
top [ -1CISTabcinqtuv ] [ -dcount ] [ -mmode ] [ -ofield ] [ -ppid ] [ -stime ] [ -Uusername ] [ number ]
Top displays the top processes on the system and periodically updates this information. If standard output is an intelligent terminal (see below) then as many processes as will fit on the terminal screen are displayed by default. Otherwise, a good number of them are shown (around 20). Raw cpu percentage is used to rank the processes. If number is given, then the top number processes will be displayed instead of the default.
Top makes a distinction between terminals that support advanced capabilities and those that do not. This distinction affects the choice of defaults for certain options. In the remainder of this document, an "intelligent" terminal is one that supports cursor addressing, clear screen, and clear to end of line. Conversely, a "dumb" terminal is one that does not support such features. If the output of top is redirected to a file, it acts as if it were being run on a dumb terminal.
Both count and number fields can be specified as "infinite", indicating that they can stretch as far as possible. This is accomplished by using any proper prefix of the keywords "infinity", "maximum", or "all". The default for count on an intelligent terminal is, in fact, infinity.
The environment variable TOP is examined for options before the command line is scanned. This enables a user to set his or her own defaults. The number of processes to display can also be specified in the environment variable TOP. The options -C, -I, -S, and -u are actually toggles. A second specification of any of these options will negate the first. Thus a user who has the environment variable TOP set to "-I" may use the command "top -I" to see idle processes.
When top is running in "interactive mode", it reads commands from the terminal and acts upon them accordingly. In this mode, the terminal is put in "CBREAK", so that a character will be processed as soon as it is typed. Almost always, a key will be pressed when top is between displays; that is, while it is waiting for time seconds to elapse. If this is the case, the command will be processed and the display will be updated immediately thereafter (reflecting any changes that the command may have specified). This happens even if the command was incorrect. If a key is pressed while top is in the middle of updating the display, it will finish the update and then process the command. Some commands require additional information, and the user will be prompted accordingly. While typing this information in, the user's erase and kill keys (as set up by the command stty) are recognized, and a newline terminates the input. Note that a control-L (^L) always redraws the current screen and a space forces an immediate update to the screen using new data.
These commands are currently recognized:
The actual display varies depending on the specific variant of Unix that the machine is running. This description may not exactly match what is seen by top running on this particular machine. Differences are listed at the end of this manual entry.
The top lines of the display show general information about the state of the system. The first line shows (on some systems) the last process id assigned to a process, the three load averages, the system uptime, and the current time. The second line displays the total number of processes followed by a breakdown of processes per state. Examples of states common to Unix systems are sleeping, running, starting, stopped, and zombie. The next line displays a percentage of time spent in each of the processor states (typically user, nice, system, idle, and iowait). These percentages show the processor activity during the time since the last update. For multi-processor systems, this information is a summation of time across all processors. The next line shows kernel-related activity (not available on all systems). The numbers shown on this line are per-second rates sampled since the last update. The exact information displayed varies between systems, but some examples are: context switches, interrupts, traps, forks, and page faults. The last one or two lines show a summary of memory and swap activity. These lines vary between systems.
The remainder of the screen displays information about individual processes. This display is similar in spirit to ps(1) but it is not exactly the same. The columns displayed by top will differ slightly between operating systems. Generally, the following fields are displayed:
Top supports the use of ANSI color in its output. By default, color is available but not used. The environment variable TOPCOLORS specifies colors to use and conditions for which they should be used. At the present time, only numbers in the summary display area can be colored. In a future version it will be possible to highlight numbers in the process display area as well. The environment variable is the only way to specify color: there is no equivalent command line option. Note that the environment variable TOPCOLOURS is also understood. The British spelling takes precedence. The use of color only works on terminals that understand and process ANSI color escape sequences.
The environment variable is a sequence of color specifications, separated by colons. Each specification takes the form tag=min,max#code where tag is the name of the value to check, min and max specify a range for the value, and code is an ANSI color code. Multiple color codes can be listed and separated with semi-colons. A missing min implies the lowest possible value (usually 0) and a missing max implies infinity. The comma must always be present. When specifying numbers for load averages, they should be multiplied by 100. For example, the specification 1min=500,1000#31 indicates that a 1 minute load average between 5 and 10 should be displayed in red. Color attributes can be combined. For example, the specification 5min=1000,#37;41 indicates that a 5 minute load average higher than 10 should be displayed with white characters on a red background. A special tag named header is used to control the color of the header for process display. It should be specified with no lower and upper limits, specifically header=,# followed by the ANSI color code.
You can see a list of color codes recognized by this installation of top with the -T option. This will also show the current set of tests used for color highlighting, as specified in the environment.
William LeFebvre
TOP user-configurable defaults for options. TOPCOLORS color specification
As with ps(1), things can change while top is collecting information for an update. The picture it gives is only a close approximation to reality.
kill(1), ps(1), stty(1), mem(4), renice(8)
Copyright (C) 1984-2007 William LeFebvre. For additional licensing information, see http://www.unixtop.org/license/
November 5, 2018 | 4th Berkeley Distribution |