Monitoring Server Processes With Top

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel. The types of system summary information shown and the types, order and size of information displayed for tasks are all user configurable.

Top provides an ongoing look at processor activity in real time. It displays a listing of the most CPU-intensive tasks on the system, and can provide an interactive interface for manipulating processes. It can sort the tasks by CPU usage, memory usage and runtime. can be better configured than the standard top from the procps suite. Most features can either be selected by an interactive command or by specifying the feature in the personal or system-wide configuration file.

Below is an example of what top will look like on an active server:

top - 10:42:15 up 6 days, 11:49,  4 users,  load average: 1.11, 0.81, 0.81
Tasks: 254 total,   2 running, 250 sleeping,   0 stopped,   2 zombie
Cpu(s): 14.6% us,  2.3% sy,  0.0% ni, 76.7% id,  6.1% wa,  0.0% hi,  0.3% si
Mem:   4043040k total,  3886812k used,   156228k free,   161988k buffers
Swap:  2040244k total,  1220276k used,   819968k free,  1506020k cached
PID     USER     PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
23611  nobody    16   0  143m  33m 3352 S  1.9  0.8   0:05.80 httpd
25816  root      16   0 51056  636  472 S  1.9  0.0   0:00.10 find
25932  nobody    16   0  140m  30m 3116 S  1.9  0.8   0:00.97 httpd
26142  root      15   0  6300 1184  768 R  1.9  0.0   0:00.01 top
26144  root      18   0 51400  964  556 R  1.9  0.0   0:00.01 egrep
1      root      16   0  4772  444  412 S  0.0  0.0   0:46.31 init
2      root      RT   0     0    0    0 S  0.0  0.0   0:02.75 migration/0
3      root      34  19     0    0    0 S  0.0  0.0   0:02.13 ksoftirqd/0
4      root      RT   0     0    0    0 S  0.0  0.0   0:03.29 migration/1
5      root      34  19     0    0    0 S  0.0  0.0   0:01.98 ksoftirqd/1
6      root      RT   0     0    0    0 S  0.0  0.0   0:03.37 migration/2
7      root      34  19     0    0    0 S  0.0  0.0   0:01.73 ksoftirqd/2

The important information that can be gleaned from this is: load average, total running processes(tasks), cpu usage, memory usage, swap usage, and the processing using the most CPU time.  For this example, an Apache process is the one using the most CPU.

If you want to sort the running processes by memory usage, while in top just hit m. This is an interactive command that will change how top sorts processes.

Some of the other flags that can be used include:

top -c This will show the entire command that is running, not just the short name

Be Sociable, Share!
Here's $75, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support.