top类似windows任务管理器,展示进程任务信息,还有cpu、memory、swap等统计信息
--1.查看版本信息
[oracle@hgora11g ~]$ top -v
top: procps version 3.2.8
usage: top -hv | -abcHimMsS -d delay -n iterations [-u user | -U user] -p pid [,pid ...]
--2.默认显示信息,按%CPU列排序
[oracle@hgora11g ~]$ top
top - 16:29:13 up 238 days, 6:12, 6 users, load average: 0.01, 0.06, 0.03
Tasks: 496 total, 1 running, 494 sleeping, 1 stopped, 0 zombie
Cpu(s): 0.3%us, 0.2%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 16335768k total, 15555392k used, 780376k free, 292632k buffers
Swap: 8241144k total, 476180k used, 7764964k free, 12907104k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10620 oracle -2 0 5037m 14m 14m S 1.7 0.1 3866:23 oracle
10630 oracle 20 0 5048m 76m 68m S 0.7 0.5 1065:37 oracle
27137 oracle 20 0 15304 1556 944 R 0.7 0.0 0:00.30 top
36 root 20 0 0 0 0 S 0.3 0.0 14:48.67 events/1
--3.按内存使用排序
[oracle@hgora11g ~]$ top -a
--4.页面刷新时间,单位为秒
[oracle@hgora11g ~]$ top -d 5
--5.不显示idle进程
[oracle@hgora11g ~]$ top -i
或者top后按i键
--6.VIRT/USED toggle,Reports USED (sum of process rss and swap total count) instead of VIRT
[oracle@hgora11g ~]$ top -m
--7.内存信息用(k/M/G)展示
[oracle@hgora11g ~]$ top -M
Mem: 15.579G total, 14.856G used, 740.629M free, 286.508M buffers
Swap: 8047.992M total, 465.020M used, 7582.973M free, 12.311G cached
--8.指定页面刷新次数
[oracle@hgora11g ~]$ top -n 5
--9.指定进程id,可以逗号分隔
[oracle@hgora11g ~]$ top -p 26835,28447
--10.-S : Cumulative time mode toggle
Starts top with the last remembered ’S’ state reversed. When ’Cumulative mode’ is On,
each process is listed with the cpu time that it and its dead children have used.
See the ’S’ interactive command for additional information regarding this mode.
--11.指定用户
[oracle@hgora11g ~]$ top -u oracle
2. FIELDS / Columns
2a. DESCRIPTIONS of Fields
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 provi-sions 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 or output.
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 second.
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.)
p: SWAP -- Swapped size (kb)
Per-process swap values are now taken from /proc/#/status VmSwap field.
q: RES -- Resident size (kb)
The non-swapped physical memory a task has used.
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 as 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 paren theses, 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 <linux/sched.h>.
Less formal documentation can also be found on the ’Fields select’ and ’Order fields’ screens.
2b. SELECTING and ORDERING Columns
After pressing the interactive commands ’f’ (Fields select) or ′o’ (Order fields) you will be shown a screen
containing the current fields string followed by names and descriptions for all fields.
Here is a sample fields string from one of top’s four windows/field groups and an explanation of the conventions used:
- Sample fields string:
ANOPQRSTUVXbcdefgjlmyzWHIK
- The order of displayed fields corresponds to the order of the letters in that string.
- If the letter is upper case the corresponding field itself will then be shown as part of the task
display (screen width permitting).
This will also be indicated by a leading asterisk (’*’), as in this excerpt:
...
* K: %CPU = CPU usage
l: TIME = CPU Time
m: TIME+ = CPU Time, hundredths
* N: %MEM = Memory usage (RES)
* O: VIRT = Virtual Image (kb)
...
Fields select screen -- the ’f’ interactive command
You toggle the display of a field by simply pressing the corresponding letter.
Order fields screen -- the ’o’ interactive command
You move a field to the left by pressing the corresponding upper case letter and to the right with the
lower case letter.
2c. SUMMARY Area Fields
The summary area fields describing CPU statistics are abbreviated. They provide information about times spent in:
us = user mode
sy = system mode
ni = low priority user mode (nice)
id = idle task
wa = I/O waiting
hi = servicing IRQs
si = servicing soft IRQs
st = steal (time given to other DomU instances)
来源自man手册:man top