top (1) is an interactive process lister for Linux and Unix
systems. It is one of the most useful programs available on the
standard Linux command line. Unlike the more standard ps tool,
which prints out a customisable listing of the processes running on
the system, top provides a real-time updating list of processes, along
with a significant amount of useful information.
A typical top output on a lightly-loaded, Linux 2.6-based system is:
top - 14:53:25 up 3:33, 1 user, load average: 1.16, 1.17, 1.20
Tasks: 83 total, 2 running, 81 sleeping, 0 stopped, 0 zombie
Cpu(s): 8.3% us, 4.3% sy, 83.7% ni, 0.0% id, 0.0% wa, 3.7% hi, 0.0% si
Mem: 514236k total, 509300k used, 4936k free, 12068k buffers
Swap: 1834288k total, 60k used, 1834228k free, 246228k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
607 rpgeek 39 19 70712 10m 2112 R 86.8 2.1 189:01.27 FahCore_65.exe
373 root 15 0 83996 45m 41m S 2.7 9.1 4:53.80 XFree86
2176 rpgeek 15 0 33924 17m 30m S 2.7 3.4 0:00.58 kdeinit
377 rpgeek 15 0 3536 2024 2572 S 1.0 0.4 0:37.77 famd
2178 rpgeek 16 0 2088 988 1876 R 0.7 0.2 0:00.15 top
480 rpgeek 16 0 27244 14m 24m S 0.3 2.9 0:09.83 kwin
2034 rpgeek 15 0 97876 68m 43m S 0.3 13.7 0:06.86 juk
1 root 16 0 1520 444 1368 S 0.0 0.1 0:05.63 init
2 root 34 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0
3 root 5 -10 0 0 0 S 0.0 0.0 0:00.46 events/0
4 root 5 -10 0 0 0 S 0.0 0.0 0:00.08 kblockd/0
This shows a wealth of instantaneous information on the running
system. It is divided between the whole-system information at the top
and the per-process information at the bottom. In addition to some
basic statistics about the system load, it displays the current CPU
, and swap
usage in the top half. The important part, however,
is the sortable list of processes in the bottom half of the
It is possible to sort the process list by any of the pieces of information shown. Sorting by PID or process name is relatively useless, adding nothing to the non-interactive ps command. It can be useful to sort processes by user, priority, or execution time, but these things change rarely and can also be done with ps. The most useful ways to sort the list are by memory usage (with a capital M keystroke) and processor utilisation (with a capital P keystroke). When doing work on a Unix system it is often useful to know what programs are using the available CPU time and memory, and top provides a list, updating in realtime, of the top users of one of these resources (this is why it's called 'top')
Top also provides an interface for management of processes, specificially sending them signals (equivalent to the 'kill' command) and changing their priority (equivalent to the 'renice' command). These features are little used compared to top's display capabilities. Top includes a terse but useful online help system, accessible by pressing '?', explaining top's complex interface for changing the display and performing process management tasks.
Due to its frequent display updates, top uses a relatively large amount of CPU time, reading the entire process table around every second. Since the process table is read while top is an active process, top itself is biased towards in the processor usage statistics, often briefly jumping to the top of the list on a relatively idle system. Top is often reniced to a lower priority than standard so that this does not disrupt more important tasks.
The interface and display style of top are familiar enough to Linux hackers that several more specialised monitor programs provide a similar interface. Examples are slabtop for probing Linux kernel memory and xrestop for monitoring the usage of X Window System server resources. Graphical programs that provide similar services to top are KSysGuard and GKrellM, both of which have larger scope and friendlier interfaces, at the price of size and complexity.
This writeup is copyright 2004-2005 D.G. Roberge and is released under the Creative Commons Attribution-NonCommercial-ShareAlike licence. Details can be found at http://creativecommons.org/licenses/by-nc-sa/2.0/ .