25.6. 进程:top

top 命令(代表“进程表”)可显示进程的列表,该列表每两秒钟刷新一次。要终止程序,请按 Q 键。参数 -n 1 在显示一次进程列表后终止程序。下面是 top -n 1 命令的示例输出:

top - 14:19:53 up 62 days,  3:35, 14 users,  load average:0.01, 0.02, 0.00 
Tasks:102 total,   7 running,  93 sleeping,   0 stopped,   2 zombie 
Cpu(s):0.3% user,   0.1% system,   0.0% nice,  99.6% idle 
Mem:514736k total,   497232k used,    17504k free,    56024k buffers 
Swap:1794736k total,   104544k used,  1690192k free,   235872k cached

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  Command 
1426 root      15   0  116m  41m  18m S  1.0  8.2  82:30.34 X 
20836 jj        15   0   820  820  612 R  1.0  0.2   0:00.03 top 
1 root      15   0   100   96   72 S  0.0  0.0   0:08.43 init 
2 root      15   0     0    0    0 S  0.0  0.0   0:04.96 keventd 
3 root      34  19     0    0    0 S  0.0  0.0   0:00.99 ksoftirqd_CPU0 
4 root      15   0     0    0    0 S  0.0  0.0   0:33.63 kswapd 
5 root      15   0     0    0    0 S  0.0  0.0   0:00.71 bdflush 
[...] 
1362 root      15   0   488  452  404 S  0.0  0.1   0:00.02 nscd 
1363 root      15   0   488  452  404 S  0.0  0.1   0:00.04 nscd 
1377 root      17   0    56    4    4 S  0.0  0.0   0:00.00 mingetty 
1379 root      18   0    56    4    4 S  0.0  0.0   0:00.01 mingetty 
1380 root      18   0    56    4    4 S  0.0  0.0   0:00.01 mingetty 

如果当 top 正在运行时按 F 键,则将打开一个菜单,使用该菜单可以对输出的格式进行全面更改。

参数 -U UID 只监视与特定用户关联的进程。将 UID 替换为用户 ID。 top -U $(id -u username) 基于用户名返回用户 UID,并显示其过程。