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 - 14:45:34 up 6:32, 2 users, load average: 0.78, 0.61, 0.59
Tasks: 110 total, 3 running, 106 sleeping, 0 stopped, 1 zombie
Cpu(s): 75.0%us, 0.6%sy, 0.0%ni, 24.4%id, 0.0%wa, 0.0%hi, 0.0%si,
0.0%st
Mem: 507680k total, 491268k used, 16412k free, 24560k buffers
Swap: 0k total, 0k used, 0k free, 316368k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2342 uwhpsc 20 0 8380 1212 796 R 300 0.2 0:28.55 jacobi2d.exe
842 root 20 0 100m 24m 9780 R 2 5.0 178:27.50 Xorg
1051 uwhpsc 20 0 40236 11m 8904 S 1 2.3 0:01.53 xfce4-terminal
1 root 20 0 3528 1864 1304 S 0 0.4 0:01.12 init
2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd
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.