top 命令实时显示进程的状态。默认状态显示的是cpu密集型的进程,并且每5秒钟更新一次。你可以通过PID的数字大小,age(),time(),resident memory usage()以及进程从启动后占用cpu的时间。
top - 20:59:18 up 4 days, 4:47, 1 user, load average: 0.00, 0.00, 0.00
Tasks: 65 total, 2 running, 63 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.1%sy, 0.0%ni, 99.6%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 500472k total, 282756k used, 217716k free, 82496k buffers
Swap: 0k total, 0k used, 0k free, 61052k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
975 root 20 0 756m 10m 8008 S 0.2 2.1 9:12.19 AliYunDun
991 root 20 0 768m 9320 7164 S 0.2 1.9 5:19.35 AliHids
842 root 20 0 463m 2588 1888 S 0.1 0.5 2:43.88 AliYunDunUpdate
1 root 20 0 19232 1512 1224 S 0.0 0.3 0:00.65 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.71 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.55 watchdog/0
7 root 20 0 0 0 0 S 0.0 0.0 0:12.40 events/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khelper
10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm
13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 xenwatch
14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 xenbus
15 root 20 0 0 0 0 S 0.0 0.0 0:01.22 sync_supers
16 root 20 0 0 0 0 S 0.0 0.0 0:01.14 bdi-default
17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/0
18 root 20 0 0 0 0 S 0.0 0.0 0:00.18 kblockd/0
19 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpid
20 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpi_notify
21 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kacpi_hotplug
如果你想提高某个进程的优先级,可以通过renice
命令,如果有摸个进程占用太多的cpu资源,可以通过kill
命令。
- top 显示出现的每个列的含义分别为:
PID: 进程描述符
USER: 进程的拥有者
PRI:进程的优先级
NI: nice level
SIZE: 进程拥有的内存(包括code segment + data segment + stack segment)
RSS: 物理内存使用
VIRT(virtul memory usage): 进程需要的虚拟内存大小
RES(resident memory usage): 常驻内存
SHARE: 和其他进程共享的物理内存空间
STAT:进程的状态,有 S=sleeping,R=running,T=stopped or traced,D=interruptible sleep(不可中断的睡眠状态),Z=zombie。
%CPU: CPU使用率
%MEM: 物理内存的使用
TIME: 进程占用的总共cpu时间
COMMAND:进程的命令
- 常用的命令:
(1) t: 用于是否显示总的统计数据,也就是下面这两行
Tasks: 65 total, 2 running, 63 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.1%sy, 0.0%ni, 99.6%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
(2)m:用户是否显示内存的信息,也就是下面这两行
Mem: 500472k total, 282756k used, 217716k free, 82496k buffers
Swap: 0k total, 0k used, 0k free, 61052k cached
(3)A: 根据单窗口切换成多窗口,可以看到四个不同的窗口,可以通过a或者w来切换多个窗口。 四个窗口的名字分别为:Def,Job,Mem,Usr
(4)f:进入一个动态配置top的screen中,可以根据自己的喜好配置top
(5)o:对top的现有配置排序(order)
(6)r:使用renice命令
(7)k:使用kill命令
- top的命令行使用方式
(1) 批量处理模式
$ top -b
加上-b
后,top显示的时候,将每一次显示的结果都打印出来,不会将上一次的结果给冲掉。
(2) 显示某个进程的信息
$ top -p pid
如果是多个进程,只要如下:
$ top -p pid1,pid2,pid3
(3) 显示某个用户的进程信息
$ top -u username
(4) 显示线程的信息,而不是进程的信息
$ top -H
(5) 设置刷屏的时间(单位为s)
$ top -d ntime
*:first-child {
margin-top: 0 !important;
}
body>*:last-child {
margin-bottom: 0 !important;
}
/* BLOCKS
=============================================================================*/
p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}
/* HEADERS
=============================================================================*/
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}
h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
h1 {
font-size: 28px;
color: #000;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777;
font-size: 14px;
}
body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}
/* LINKS
=============================================================================*/
a {
color: #4183C4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* LISTS
=============================================================================*/
ul, ol {
padding-left: 30px;
}
ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}
dl {
padding: 0;
}
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}
dl dt:first-child {
padding: 0;
}
dl dt>:first-child {
margin-top: 0px;
}
dl dt>:last-child {
margin-bottom: 0px;
}
dl dd {
margin: 0 0 15px;
padding: 0 15px;
}
dl dd>:first-child {
margin-top: 0px;
}
dl dd>:last-child {
margin-bottom: 0px;
}
/* CODE
=============================================================================*/
pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}
code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}
pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
pre code, pre tt {
background-color: transparent;
border: none;
}
kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}
/* QUOTES
=============================================================================*/
blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
blockquote>:first-child {
margin-top: 0px;
}
blockquote>:last-child {
margin-bottom: 0px;
}
/* HORIZONTAL RULES
=============================================================================*/
hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}
/* TABLES
=============================================================================*/
table th {
font-weight: bold;
}
table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}
table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
/* IMAGES
=============================================================================*/
img {
max-width: 100%
}
-->