linux daily --top

linux top命令

1. 概述(照抄man):

The top program provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by linux kernel. The types of system summary information shown and types, order and size of information displayed for tasks are all user configurable and that configuration can be made persistant across restart.

 

2. 参数:

-d:列表内容更新时间,后接秒数: top -d 2 (每2s刷新一次列表)

-b:以批次方式执行,后接-n 加数字,表示执行几次,并可以将结果输出到文件:top -b -n2 > /path/x.txt (执行top2次并将结果输出到/path/x.txt)

-p:制定某个PID进行观测:top -p 13100 (查看PID为13100的进程的情况)

在启动top后:

输入k:

top - 12:31:33 up 20:19, 4 users, load average: 0.17, 0.32, 0.32
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.4%us, 0.6%sy, 2.8%ni, 96.1%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 3637960k total, 2522020k used, 1115940k free, 166476k buffers
Swap: 3775236k total, 0k used, 3775236k free, 1349512k cached
PID to kill: 13100
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13100 meroc 21 1 1680m 196m 40m S 14 5.5 16:49.79 chromium-browse

 

可以给指定PID的进程一个讯号。

输入r:

top - 12:32:40 up 20:20, 4 users, load average: 0.20, 0.30, 0.31
Mem: 3637960k total, 2526824k used, 1111136k free, 166568k buffers
Swap: 3775236k total, 0k used, 3775236k free, 1349444k cached
PID to renice: 13100
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13100 meroc 21 1 1680m 196m 40m S 13 5.5 16:58.29 chromium-browse

可以重新指定进程的NI值(即nice:优先级):

top - 12:32:40 up 20:20, 4 users, load average: 0.20, 0.30, 0.31
Mem: 3637960k total, 2526824k used, 1111136k free, 166568k buffers
Swap: 3775236k total, 0k used, 3775236k free, 1349444k cached
Renice PID 13100 to value: 2
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13100 meroc 21 1 1680m 196m 40m S 13 5.5 16:58.29 chromium-browse

 

top - 12:36:03 up 20:24, 4 users, load average: 0.23, 0.34, 0.33
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
Cpu(s): 2.4%us, 1.1%sy, 2.7%ni, 93.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 3637960k total, 2535472k used, 1102488k free, 166824k buffers
Swap: 3775236k total, 0k used, 3775236k free, 1354968k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13100 meroc 22 2 1680m 196m 40m S 13 5.5 17:24.07 chromium-browse

 

3.列表属性:

top - 12:36:03 up 20:24, 4 users, load average: 0.23, 0.34, 0.33        

--当前时间,系统运行时间,链接用户数,系统负载(3个数值分别为:1,5,15分钟到现在的平均值);其实这行可以用uptime命令显示

Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie            

--进程总数,运行进程数,睡眠进程数,停止进程数,僵死进程数

Cpu(s): 2.4%us, 1.1%sy, 2.7%ni, 93.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st   

--用户CPU占用百分比,系统CPU占用百分比,用户进程空间中改变了进程优先级的进程所占百分比,空闲CPU百分比,等待输入输出的CPU所占百分比
Mem: 3637960k total, 2535472k used, 1102488k free, 166824k buffers              

 --内存总空间,内存已用空间,内存剩余空间,作为内核缓存的内存大小
Swap: 3775236k total, 0k used, 3775236k free, 1354968k cached         

--交换区总量,交换区使用量,交换区剩余大小,缓冲交换区总量。

PID:Process ID

USER:process所有者的ID

PR:priority,优先级,越小越先被执行

NI:nice,优先级相关,也是越小越先被执行

%CPU:CPU使用率

%MEM:内存使用率

TIME+:CPU使用时间累加

linux daily --top

上一篇:《罗辑思维》读书笔记及思维导图


下一篇:TopCoder SRM 606 Div2 题解