< Previous | Contents | Next >
Viewing Processes Dynamically With top
While the ps command can reveal a lot about what the machine is doing, it provides only a snapshot of the machine's state at the moment the ps command is executed. To see a more dynamic view of the machine's activity, we use the top command:
[me@linuxbox ~]$ top
[me@linuxbox ~]$ top
The top program displays a continuously updating (by default, every 3 seconds) display of the system processes listed in order of process activity. The name “top” comes from the fact that the top program is used to see the “top” processes on the system. The top display consists of two parts: a system summary at the top of the display, followed by a table of processes sorted by CPU activity:
top - 14:59:20 up 6:30, 2 users, load average: 0.07, 0.02, 0.00
Tasks: 109 total, 1 running, 106 sleeping, 0 stopped, 2 zombie Cpu(s): 0.7%us, 1.0%sy, 0.0%ni, 98.3%id, 0.0%wa, 0.0%hi, 0.0%si Mem: 319496k total, 314860k used, 4636k free, 19392k buff Swap: 875500k total, 149128k used, 726372k free, 114676k cach
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6244 me 39 19 31752 3124 2188 S 6.3 1.0 16:24.42 trackerd
11071 me 20 0 2304 1092 840 R 1.3 0.3 0:00.14 top
6180 me 20 0 2700 1100 772 S 0.7 0.3 0:03.66 dbus-dae
6321 me 20 0 20944 7248 6560 S 0.7 2.3 2:51.38 multiloa
4955 root 20 0 104m 9668 5776 S 0.3 3.0 2:19.39 Xorg
1 root 20 0 2976 528 476 S 0.0 0.2 0:03.14 init
2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migratio
4 root 15 -5 0 0 0 S 0.0 0.0 0:00.72 ksoftirq
5 root RT -5 0 0 0 S 0.0 0.0 0:00.04 watchdog
6 root 15 -5 0 0 0 S 0.0 0.0 0:00.42 events/0
7 root 15 -5 0 0 0 S 0.0 0.0 0:00.06 khelper
41 root 15 -5 0 0 0 S 0.0 0.0 0:01.08 kblockd/
67 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kseriod
114 root 20 0 0 0 0 S 0.0 0.0 0:01.62 pdflush
116 root 15 -5 0 0 0 S 0.0 0.0 0:02.44 kswapd0
The system summary contains a lot of good stuff. Here's a rundown:
Table 10-3: top Information Fields
Row | Field | Meaning |
1 | top | Name of the program. |
14:59:20 | Current time of day. | |
up 6:30 | This is called uptime. It is the amount of time since the machine was last booted. In this example, the system has been up for six and a half hours. | |
2 users | There are two users logged in. | |
load average: | Load average refers to the number of processes |
that are waiting to run, that is, the number of processes that are in a runnable state and are sharing the CPU. Three values are shown, each for a different period of time. The first is the average for the last 60 seconds, the next the previous 5 minutes, and finally the previous 15 minutes. Values under 1.0 indicate that the machine is not busy. | ||
2 | Tasks: | This summarizes the number of processes and their various process states. |
3 | Cpu(s): | This row describes the character of the activities that the CPU is performing. |
0.7%us | 0.7% of the CPU is being used for user processes. This means processes outside of the kernel itself. | |
1.0%sy | 1.0% of the CPU is being used for system (kernel) processes. | |
0.0%ni | 0.0% of the CPU is being used by “nice” (low priority) processes. | |
98.3%id | 98.3% of the CPU is idle. | |
0.0%wa | 0.0% of the CPU is waiting for I/O. | |
4 | Mem: | Shows how physical RAM is being used. |
5 | Swap: | Shows how swap space (virtual memory) is being used. |
The top program accepts a number of keyboard commands. The two most interesting are
h, which displays the program's help screen, and q, which quits top.
Both major desktop environments provide graphical applications that display information similar to top (in much the same way that Task Manager in Windows works), but top is better than the graphical versions because it is faster and it consumes far fewer system re- sources. After all, our system monitor program shouldn't be the source of the system slowdown that we are trying to track.