前几天跟一人交流的时候,讨论到系统监控命令,对于其中的TOP命令,交流下来发现自己并不是很了解这个命令正在的用法,以前都只贪图多(vmstat,iostat),而没有仔细了解具体详细的用法,回来后深感惭愧。今天就在这仔细整理下top命令的几个常见option。
1.帮助:h 这个是你在忘记命令下最好的帮手,学什么命令第一个要学习就是help 。具体的界面如下所示
—————————————————————————–
Help for Interactive Commands – procps version 3.2.8
Window 1:Def: Cumulative mode On. System: Delay 1.0 secs; Secure mode Off.
Z,B Global: ‘Z’ change color mappings; ‘B’ disable/enable bold
l,t,m Toggle Summaries: ‘l’ load avg; ‘t’ task/cpu stats; ‘m’ mem info
1,I Toggle SMP view: ‘1’ single/separate states; ‘I’ Irix/Solaris mode
f,o . Fields/Columns: ‘f’ add or remove; ‘o’ change display order
F or O . Select sort field
<,> . Move sort field: ‘<‘ next col left; ‘>’ next col right
R,H . Toggle: ‘R’ normal/reverse sort; ‘H’ show threads
c,i,S . Toggle: ‘c’ cmd name/line; ‘i’ idle tasks; ‘S’ cumulative time
x,y . Toggle highlights: ‘x’ sort field; ‘y’ running tasks
z,b . Toggle: ‘z’ color/mono; ‘b’ bold/reverse (only if ‘x’ or ‘y’)
u . Show specific user only
n or # . Set maximum tasks displayed
k,r Manipulate tasks: ‘k’ kill; ‘r’ renice
d or s Set update interval
W Write configuration file
q Quit
( commands shown with ‘.’ require a visible task display window )
Press ‘h’ or ‘?’ for help with Windows,
any other key to continue
—————————————————————————–
我们看上面有很多,只挑有用的讲解下,类如Z,B这种设置颜色个格式的就不提了。进入正题。
top – 11:21:59 up 24 min, 0 users, load average: 0.00, 0.03, 0.06
Tasks: 130 total, 1 running, 128 sleeping, 0 stopped, 1 zombie
Cpu(s): 0.7%us, 2.2%sy, 0.0%ni, 97.2%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3606920k total, 1255552k used, 2351368k free, 174180k buffers
Swap: 1046524k total, 0k used, 1046524k free, 582400k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 24156 2196 1324 S 0 0.1 0:00.57 init
2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0 0.0 0:00.45 ksoftirqd/0
4 root 20 0 0 0 0 S 0 0.0 0:00.31 kworker/0:0
1)l,t,m
l:隐藏 top行信息
t:隐藏 Tasks Cpus 两行的信息
m:隐藏 Mem Swap 两行的信息
2)1,I
1:若是有多个CPU,显示多个cpu的具体信息
I:开启Solaris模式
3) F,O 这两个完成相同功能,比较重要,若是你希望查找一些mem比较好的进程,就需要使用到这个了。看下面具体信息
Current Sort Field: K for window 1:Def
Select sort field via field letter, type any other key to return
a: PID = Process Id not those in column display. Thus,
b: PPID = Parent Process Pid the TTY & WCHAN fields will violate
c: RUSER = Real user name strict ASCII collating sequence.
d: UID = User Id (shame on you if WCHAN is chosen)
e: USER = User Name
f: GROUP = Group Name
g: TTY = Controlling Tty
h: PR = Priority
i: NI = Nice value
j: P = Last used cpu (SMP)
* K: %CPU = CPU usage
l: TIME = CPU Time
m: TIME+ = CPU Time, hundredths
n: %MEM = Memory usage (RES)
o: VIRT = Virtual Image (kb)
p: SWAP = Swapped size (kb)
q: RES = Resident size (kb)
r: CODE = Code size (kb)
s: DATA = Data+Stack size (kb)
t: SHR = Shared Mem size (kb)
u: nFLT = Page Fault count
v: nDRT = Dirty Pages count
w: S = Process Status
x: COMMAND = Command name/line
y: WCHAN = Sleeping in Function
z: Flags = Task Flags <sched.h>
不同的选择会按照不同的参数进行排序。比较多的就是 K 和 n 按照cpu占用率或是内存进行排序
4)R,H
R:正序或是逆序排列,这个配合F,O使用,选定按照何种方式排序后,R来进行正序或是逆序查看。
H: 显示线程信息
5)u
按照某个用户进行具体的查看
6)k,r
k:杀死某个进行 效果同 kill ,需要输入pid
r:重新设定优先进程占用时间
7) d or s
设置取数据的间隔时间
8) o (小写的) 改变展示的列及列的顺序
0 条评论。