top: Display Top CPU Processes

The top command is a system monitor tool that produces a frequently-updated list of processes. By default, the processes are ordered by percentage of CPU usage, with only the “top” CPU consumers shown. top shows how much processing power and memory are being used, as well as other information about the running processes. Some versions of top allow extensive customization of the display, such as choice of columns or sorting method. top is useful for system administrators, as it shows which users and processes are consuming the most system resources at any given time.

top - 14:10:07 up 307 days,  5:49,  8 users,  load average: 0.11, 0.11, 0.10
Tasks: 500 total,   1 running, 499 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1% us,  0.2% sy,  0.0% ni, 99.1% id,  0.7% wa,  0.0% hi,  0.0% si
Mem:   8244276k total,  7999728k used,   244548k free,   239204k buffers
Swap: 16781032k total,  8612488k used,  8168544k free,  4303028k cached

PID  USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
7945 root      16   0  2028 1168  700 R  0.7  0.0   0:00.06 top
3736 root      25   0 93124  844  668 S  0.3  0.0   1154:18 hpasmd
1    root      16   0   588   68   44 S  0.0  0.0   0:39.96 init
2    root      RT   0     0    0    0 S  0.0  0.0   0:28.52 migration/0
3    root      34  19     0    0    0 S  0.0  0.0   0:02.00 ksoftirqd/0
4    root      RT   0     0    0    0 S  0.0  0.0   0:55.83 migration/1
5    root      34  19     0    0    0 S  0.0  0.0   0:02.57 ksoftirqd/1
6    root      RT   0     0    0    0 S  0.0  0.0   6:49.69 migration/2
7    root      34  19     0    0    0 S  0.0  0.0   0:02.90 ksoftirqd/2
8    root      RT   0     0    0    0 S  0.0  0.0   0:28.74 migration/3
9    root      34  19     0    0    0 S  0.0  0.0   0:02.05 ksoftirqd/3
10   root       5 -10     0    0    0 S  0.0  0.0   0:00.21 events/0

 

Command Options:
-d : Specifies the delay between screen updates. You can change this with the s interactive command.
-p : Monitor only processes with given process id. This flag can be given up to twenty times. This option is neither available interactively nor can it be put into the configuration file.
-q : This causes top to refresh without any delay. If the caller has superuser privileges, top runs with the highest possible priority.
-S : Specifies cumulative mode, where each process is listed with the CPU time that it as well as its dead children has spent. This is like the -S flag to ps(1). See the discussion below of the S interactive command.
-s : Tells top to run in secure mode. This disables the potentially dangerous of the interactive commands (see below). A secure top is a nifty thing to leave running on a spare terminal.
-i : Start top ignoring any idle or zombie processes. See the interactive command i below.
-C : display total CPU states instead of individual CPUs. This option only affects SMP systems.
-c : display command line instead of the command name only. The default behavior has been changed as this seems to be more useful.
-H : Show all threads.
-n : Number of iterations. Update the display this number of times and then exit.
-b : Batch mode. Useful for sending output from top to other programs or to a file. In this mode, top will not accept command line input. It runs until it produces the number of iterations requested with the n option or until killed. Output is plain text suitable for display on a dumb terminal.

Fields Description:
“uptime” : This line displays the time the system has been up, and the three load averages for the system. The load averages are the average number of process ready to run during the last 1, 5 and 15 minutes. This line is just like the output of uptime(1). The uptime display may be toggled by the interactive l command.
processes : The total number of processes running at the time of the last update. This is also broken down into the number of tasks which are running, sleeping, stopped, or undead. The processes and states display may be toggled by the t interactive command.
“CPU states” : Shows the percentage of CPU time in user mode, system mode, niced tasks, iowait and idle. (Niced tasks are only those whose nice value is positive.) Time spent in niced tasks will also be counted in system and user time, so the total will be more than 100%. The processes and states display may be toggled by the t interactive command.
Mem : Statistics on memory usage, including total available memory, free memory, used memory, shared memory, and memory used for buffers. The display of memory information may be toggled by the m interactive command.
Swap : Statistics on swap space, including total swap space, available swap space, and used swap space. This and Mem are just like the output of free(1).
PID : The process ID of each task.
PPID : The parent process ID each task.
UID : The user ID of the task’s owner.
USER : The user name of the task’s owner.
PRI : The priority of the task.
NI : The nice value of the task. Negative nice values are higher priority.
SIZE : The size of the task’s code plus data plus stack space, in kilobytes, is shown here.
TSIZE : The code size of the task. This gives strange values for kernel processes and is broken for ELF processes.
DSIZE : Data + Stack size. This is broken for ELF processes.
TRS : Text resident size.
SWAP : Size of the swapped out part of the task.
D : Size of pages marked dirty.
LC : Last used processor. (That this changes from time to time is not a bug; Linux intentionally uses weak affinity. Also notice that the very act of running top may break weak affinity and cause more processes to change current CPU more often because of the extra demand for CPU time.)
RSS : The total amount of physical memory used by the task, in kilobytes, is shown here. For ELF processes used library pages are counted here, for a.out processes not.
SHARE : The amount of shared memory used by the task is shown in this column.
STAT : The state of the task is shown here. The state is either S for sleeping, D for uninterruptible sleep, R for running, Z for zombies, or T for stopped or traced. These states are modified by trailing < for a process with negative nice value, N for a process with positive nice value, W for a swapped out process (this does not work correctly for kernel processes).
WCHAN : depending on the availability of either /boot/psdatabase or the kernel link map /boot/System.map this shows the address or the name of the kernel function the task currently is sleeping in.
TIME : Total CPU time the task has used since it started. If cumulative mode is on, this also includes the CPU time used by the process’s children which have died. You can set cumulative mode with the S command line option or toggle it with the interactive command S. The header line will then be changed to CTIME.
%CPU : The task’s share of the CPU time since the last screen update, expressed as a percentage of total CPU time per processor.
%MEM : The task’s share of the physical memory.
COMMAND : The task’s command name, which will be truncated if it is too long to be displayed on one line. Tasks in memory will have a full command line, but swapped-out tasks will only have the name of the program in parentheses (for example, “(getty)”).

You May Also Like

Leave a Reply?