The Unix top command is a very useful way to see what programs are currently running on the system and how heavily they are using system resources. (The command is named “top” because it shows the top users of the system.) It is a good idea to run top to check for other users running large programs before running one yourself on a shared computer (such as the Applied Math servers), and you can also use it to monitor your own programs.
To run top, simply type:
$ top
at the command line. top will fill your terminal window with a real-time display of system status, with a summary area displaying general information about memory and processor usage in the first few lines, followed by a list of processes and information about them. An example display is shown below, with the process list truncated for brevity:
top - 16:07:52 up 1:45, 2 users, load average: 0.05, 0.12, 0.09
Tasks: 150 total, 2 running, 148 sleeping, 0 stopped, 0 zombie
Cpu(s): 3.2%us, 2.3%sy, 0.0%ni, 94.2%id, 0.2%wa, 0.0%hi, 0.2%si, 0.0%st
Mem: 1018060k total, 631284k used, 386776k free, 69444k buffers
Swap: 498004k total, 0k used, 498004k free, 283880k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2080 grady 20 0 300m 96m 26m S 0 9.7 10:50.53 firefox
2757 grady 20 0 71300 36m 11m S 0 3.7 0:16.51 evince
1859 grady 20 0 60592 20m 12m S 0 2.1 0:06.93 netbook-launche
1858 grady 20 0 54864 18m 10m S 0 1.9 0:00.76 nautilus
939 root 20 0 48552 17m 9068 S 4 1.7 3:41.44 Xorg
1909 grady 20 0 28836 16m 10m S 0 1.7 0:00.88 eee-control-tra
2640 grady 20 0 27812 16m 9540 S 0 1.6 0:08.10 emacs
1856 grady 20 0 40312 16m 11m S 0 1.6 0:08.10 gnome-panel
1907 grady 20 0 29444 14m 8144 S 0 1.4 0:00.41 python
1902 grady 20 0 36924 13m 9980 S 0 1.4 0:09.76 nm-applet
2489 grady 20 0 38560 13m 9900 S 3 1.3 0:10.42 gnome-terminal
The summary area shows a great deal of information about the general state of the system. The main highlights are the third through fifth lines, which show CPU and memory usage.
CPU is given as percentages spent doing various tasks. The abbreviations have the following meanings:
The fourth and fifth lines show the usage of physical (i.e. actual RAM chips) and virtual memory. The first three fields are mostly self-explanatory, though on Linux the used memory includes disk cache. (Linux uses RAM that’s not allocated by programs to cache data from the disk, which can improve the computer’s performance because RAM is much faster than disk.) buffers gives the amount of memory used for I/O buffering, and cached is the amount used by the disk cache. Programs’ memory allocation takes priority over buffering and caching, so the total amount of memory available is the sum free + buffers + cached.
The task area gives a sorted list of the processes currently running on your system. By default, the list is sorted in descending order of CPU usage; the example display above is sorted by memory usage instead. Many different fields can be displayed in the task area; the default fields are:
There are many useful commands you can issue to top; only a few of them are listed here. For more information, see the top manual page.
Command | Meaning |
---|---|
q | Quit |
? | Help |
u | Select processes belonging to a particular user. Useful on shared systems. |
k | Kill a process |
F | Select which field to sort by |
For more information, see the quick reference guide at http://www.oreillynet.com/linux/cmd/cmd.csp?path=t/top, or type man top in a Unix terminal window to read the manual page.