TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中CPU最“敏感”的任务列表.该命令可以按CPU使用.内存使用和执行时间对任务进行排序;而且该命令的很多特性都可以通过交互式命令或者在个人定制文件中进行设定. top - 12:38:33 up 50 days, 23:15, 7 users, load average: 60.58, 61.14, 61.22 Tasks: 203 total, 60 running, 139 sleeping, 4 stopped, 0 zombie Cpu(s) : 27.0%us, 73.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1939780k total, 1375280k used, 564500k free, 109680k buffers Swap: 4401800k total, 497456k used, 3904344k free, 848712k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 4338 oracle 25 0 627m 209m 207m R 0 11.0 297:14.76 oracle 4267 oracle 25 0 626m 144m 143m R 6 7.6 89:16.62 oracle 3458 oracle 25 0 672m 133m 124m R 0 7.1 1283:08 oracle 3478 oracle 25 0 672m 124m 115m R 0 6.6 1272:30 oracle 3395 oracle 25 0 672m 122m 113m R 0 6.5 1270:03 oracle 3480 oracle 25 0 672m 122m 109m R 8 6.4 1274:13 oracle 3399 oracle 25 0 672m 121m 110m R 0 6.4 1279:37 oracle 4261 oracle 25 0 634m 100m 99m R 0 5.3 86:13.90 oracle 25737 oracle 25 0 632m 81m 74m R 0 4.3 272:35.42 oracle 7072 oracle 25 0 626m 72m 71m R 0 3.8 6:35.68 oracle 16073 oracle 25 0 630m 68m 63m R 8 3.6 175:20.36 oracle 16140 oracle 25 0 630m 66m 60m R 0 3.5 175:13.42 oracle 16122 oracle 25 0 630m 66m 60m R 0 3.5 176:47.73 oracle 786 oracle 25 0 627m 63m 63m R 0 3.4 1:54.93 oracle 4271 oracle 25 0 627m 59m 58m R 8 3.1 86:09.64 oracle 4273 oracle 25 0 627m 57m 56m R 8 3.0 84:38.20 oracle 22670 oracle 25 0 626m 50m 49m R 0 2.7 84:55.82 oracle 一. TOP前五行统计信息 统计信息区前五行是系统整体的统计信息。 1. 第一行是任务队列信息 同 uptime 命令的执行结果: [root@localhost ~]# uptime 13:22:30 up 8 min, 4 users, load average: 0.14, 0.38, 0.25 其内容如下: 12:38:33当前时间 up 50days系统运行时间,格式为时:分 1 user当前登录用户数 load average: 0.06, 0.60, 0.48系统负载,即任务队列的平均长度。 三个数值分别为 1分钟、5分钟、15分钟前到现在的平均值。 2. 第二、三行为进程和CPU的信息 当有多个CPU时,这些内容可能会超过两行。内容如下: Tasks: 29 total进程总数 1 running正在运行的进程数 28 sleeping睡眠的进程数 0 stopped停止的进程数 0 zombie僵尸进程数 Cpu(s): 0.3% us用户空间占用CPU百分比 1.0% sy内核空间占用CPU百分比 0.0% ni用户进程空间内改变过优先级的进程占用CPU百分比 98.7% id空闲CPU百分比 0.0% wa等待输入输出的CPU时间百分比 0.0% hi 0.0% si 3. 第四五行为内存信息。 内容如下: Mem: 191272k total物理内存总量 173656k used使用的物理内存总量 17616k free空闲内存总量 22052k buffers用作内核缓存的内存量 Swap: 192772k total交换区总量 0k used使用的交换区总量 192772k free空闲交换区总量
123988k cached缓冲的交换区总量。 内存中的内容被换出到交换区,而后又被换入到内存,但使用过的交换区尚未被覆盖, 该数值即为这些内容已存在于内存中 的交换区的大小。相应的内存再次被换出时可不必再对交换区写入。 二. 进程信息 列名含义 PID进程id PPID父进程id RUSERReal user name UID进程所有者的用户id USER进程所有者的用户名 GROUP进程所有者的组名 TTY启动进程的终端名。不是从终端启动的进程则显示为 ? PR优先级 NInice值。负值表示高优先级,正值表示低优先级 P最后使用的CPU,仅在多CPU环境下有意义 %CPU上次更新到现在的CPU时间占用百分比 TIME进程使用的CPU时间总计,单位秒 TIME+进程使用的CPU时间总计,单位1/100秒 %MEM进程使用的物理内存百分比 VIRT进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES SWAP进程使用的虚拟内存中,被换出的大小,单位kb。 RES进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA CODE可执行代码占用的物理内存大小,单位kb DATA可执行代码以外的部分(数据段+栈)占用的物理内存大小,单位kb SHR共享内存大小,单位kb nFLT页面错误次数 nDRT最后一次写入到现在,被修改过的页面数。 S进程状态。 D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程 COMMAND命令名/命令行 WCHAN若该进程在睡眠,则显示睡眠中的系统函数名 Flags任务标志,参考 sched.h top 的man 命令解释如下: Listed below are top's available fields. They are always associated with the letter shown, regardless of the position you may have established for them with the 'o' (Order fields) interactive command.Any field is selectable as the sort field, and you control whether they are sorted high-to-low or low-to-high. For additional information on sort provisions see topic 3c. TASK Area Commands. a: PID -- Process Id The task's unique process ID, which periodically wraps, though never restarting at zero. b: PPID -- Parent Process Pid The process ID of a task's parent. c: RUSER -- Real User Name The real user name of the task's owner. d: UID -- User Id The effective user ID of the task's owner. e: USER -- User Name The effective user name of the task's owner. f: GROUP -- Group Name The effective group name of the task's owner. g: TTY -- Controlling Tty The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input oroutput. However, a task need not be associated with a terminal, in which case you'll see '?' displayed. h: PR -- Priority The priority of the task. i: NI -- Nice value The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task's dispatchability. j: P -- Last used CPU (SMP) A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time). k: %CPU -- CPU usage The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command. l: TIME -- CPU Time Total CPU time the task has used since it started. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children has used. You toggle 'Cumulative mode' with 'S', which is a command-line option and an interactive command. See the 'S' interactive command for additional information regarding this mode. m: TIME+ -- CPU Time, hundredths The same as 'TIME', but reflecting more granularity through hundredths of a sec ond. n: %MEM -- Memory usage (RES) A task's currently used share of available physical memory. o: VIRT -- Virtual Image (kb) The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out. (Note: you can define the STATSIZE=1 environment variable and the VIRT will be calculated from the /proc/#/state VmSize field.) VIRT = SWAP + RES. p: SWAP -- Swapped size (kb) The swapped out portion of a task's total virtual memory image. q: RES -- Resident size (kb) The non-swapped physical memory a task has used. RES = CODE + DATA. r: CODE -- Code size (kb) The amount of physical memory devoted to executable code, also known as the'text resident set' size or TRS. s: DATA -- Data+Stack size (kb) The amount of physical memory devoted to other than executable code, also known the 'data resident set' size or DRS. t: SHR -- Shared Mem size (kb) The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes. u: nFLT -- Page Fault count The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available. v: nDRT -- Dirty Pages count The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page. w: S -- Process Status The status of the task which can be one of: 'D' = uninterruptible sleep 'R' = running 'S' = sleeping 'T' = traced or stopped 'Z' = zombie Tasks shown as running should be more properly thought of as 'ready to run' --their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top's delay interval and nice value. x: Command -- Command line or Program name Display the command line used to start a task or the name of the associated program. You toggle between command line and name with 'c', which is both a command-line option and an interactive command. When you've chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in parentheses, as in this example: ( mdrecoveryd ) Either form of display is subject to potential truncation if it's too long to fit in this field's current width. That width depends upon other fields selected, their order and the current screen width. Note: The 'Command' field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines. y: WCHAN -- Sleeping in Function Depending on the availability of the kernel link map ('System.map'), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash ('-') in this column. Note: By displaying this field, top's own working set will be increased by over 700Kb. Your only means of reducing that overhead will be to stop and restart top. z: Flags -- Task Flags
This column represents the task's current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in
默认情况下仅显示比较重要的 PID、USER、PR、NI、VIRT、RES、SHR、S、%CPU、%MEM、TIME+、COMMAND 列。 |