Linux—top命令的信息

253 阅读9分钟

top命令输出的信息

top - 20:20:41 up 196 days,  5:10,  1 user,  load average: 0.05, 0.10, 0.07
Tasks: 137 total,   1 running, 136 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  1.3 sy,  0.0 ni, 97.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1882236 total,    73604 free,  1532252 used,   276380 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   163256 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
12372 root      10 -10  135464  11472   5620 S  1.0  0.6 171:07.88 AliYunDun
 3343 root      10 -10  436896   1072    496 S  0.3  0.1 141:45.58 AliSecGuard
 6748 1000      20   0 3052612  68404      0 S  0.3  3.6  26:15.24 java
11037 root      20   0 3706904 905080    800 S  0.3 48.1  83:17.49 java
11606 root      20   0 2017020  70332   1056 S  0.3  3.7  43:45.41 java
13533 root      20   0  162036   2324   1600 R  0.3  0.1   0:00.02 top
14151 root      20   0  607064   7256    392 S  0.3  0.4 100:28.58 docker-containe
18624 root      20   0   10.1g   4944   1288 S  0.3  0.3 410:08.84 etcd
18884 root      20   0  220320  14592    620 S  0.3  0.8  52:34.28 supervisord
    1 root      20   0   43832   2928   1388 S  0.0  0.2   3:04.89 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.11 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   1:59.87 ksoftirqd/0
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 S  0.0  0.0  32:00.65 rcu_sched
   10 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 lru-add-drain
   11 root      rt   0       0      0      0 S  0.0  0.0   1:34.21 watchdog/0
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   15 root      20   0       0      0      0 S  0.0  0.0   0:07.48 khungtaskd
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   21 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
   22 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md
   23 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 edac-poller
   24 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 watchdogd
   30 root      20   0       0      0      0 S  0.0  0.0   0:20.01 kswapd0
   31 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd
   32 root      39  19       0      0      0 S  0.0  0.0   0:28.88 khugepaged
   33 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 crypto
   41 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kthrotld
   43 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kmpath_rdacd
   44 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kaluad
   45 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kpsmoused
   46 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 ipv6_addrconf
   59 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 deferwq
   90 root      20   0       0      0      0 S  0.0  0.0   0:03.22 kauditd
  630 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 ata_sff
  678 root      20   0       0      0      0 S  0.0  0.0   0:00.00 scsi_eh_0
  679 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 scsi_tmf_0

第一行【任务队列信息,同uptime命令的执行结果】

系统时间:20:20:41 
运行时间:up 196 days,
当前登录用户:1 user,
负载均衡:load average: 0.05, 0.10, 0.07

average后面的三个数分别是1分钟、5分钟、15分钟的负载情况;
load average数据是每隔5秒钟检查一次活跃的进程数,然后按特定算法计算出的数值,
如果这个数除以逻辑CPU的数量,结果高于5的时候就表明系统在超负荷运转了。

第二行【Tasks — 任务(进程)】

Tasks: 137 total,   1 running, 136 sleeping,   0 stopped,   0 zombie
总进程:137 total, 运行:1 running, 休眠:149 sleeping, 停止: 0 stopped, 僵尸进程: 0 zombie
含义字段数值
总进程Tasks137 total
运行中的进程数量running1 running
休眠中的进程数量sleeping149 sleeping
停止的进程数量stopped0 stopped
僵尸进程数量zombie0 zombie

第三行【cpu状态信息】

%Cpu(s):  1.0 us,  1.3 sy,  0.0 ni, 97.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
含义字段数值
用户空间占用CPU的百分比user space1.0 us
内核空间占用CPU的百分比sysctl1.3 sy
改变过优先级的进程占用CPU的百分比0.0 ni
空闲CPU百分比idolt97.7 id
IO等待占用CPU的百分比wait0.0 wa
硬中断占用CPU的百分比Hardware IRQ0.0 hi
软中断占用CPU的百分比Software Interrupts0.0 si

第四行【内存状态信息】

KiB Mem :  1882236 total,    73604 free,  1532252 used,   276380 buff/cache
含义字段数值
总内存大小total1882236 total
空闲内存大小free73604 free
已使用内存大小used1532252 used
缓存的内存量buff/cache276380 buff/cache

第五行【swap交换分区信息】

KiB Swap:        0 total,        0 free,        0 used.   163256 avail Mem
含义字段数值
交换区总量total0
交换区空想free0
交换区已使用used0
缓冲的交换区总量avail Mem163256

第六行【空行】

第七行【单个进程信息】

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
12372 root      10 -10  135464  11472   5620 S  1.0  0.6 171:07.88 AliYunDun
字段含义数值
PID进程id12372
USER进程所有者root
PR进程优先级10
NInice值,负值表示高优先级,正值表示低优先级-10
VIRT进程使用的虚拟内存总量,单位kb,VIRT=SWAP+RES135464
RES进程使用的、未被换出的物理内存大小,单位kb;RES=CODE+DATA11472
SHR共享内存大小,单位kb5620
S进程状态;D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程S
%CPU上次更新到现在的CPU时间占用百分比1.0
%MEM进程使用的物理内存百分比0.6
TIME+进程使用的CPU时间总计,单位1/100秒171:07.88
COMMAND进程名称(命令名/命令行)AliYunDun

top命令的参数

top [-] [d] [p] [q] [c] [C] [S] [s] [n]

字段含义
d指定每两次屏幕信息刷新之间的时间间隔,当然用户可以使用s交互命令来改变之
p通过指定监控进程ID来仅仅监控某个进程的状态
q该选项将使top没有任何延迟的进行刷新。如果调用程序有超级用户权限,那么top将以尽可能高的优先级运行
S指定累计模式
s使top命令在安全模式中运行。这将去除交互命令所带来的潜在危险
i使top不显示任何闲置或者僵死进程
c显示整个命令行而不只是显示命令名

使用案例

查看某个进程里面的线程的占用情况

[root@~]$top -H -p 12372
top - 21:13:37 up 196 days,  6:02,  1 user,  load average: 0.13, 0.07, 0.05
Threads:  23 total,   0 running,  23 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.3 us,  1.0 sy,  0.0 ni, 97.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1882236 total,    82024 free,  1532352 used,   267860 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   163132 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
12373 root      10 -10  135464  10868   5016 S  0.3  0.6   3:08.66 AliYunDun
12386 root      10 -10  135464  10868   5016 S  0.3  0.6  62:22.70 AliYunDun
12387 root      10 -10  135464  10868   5016 S  0.3  0.6   6:36.34 AliYunDun
12393 root      10 -10  135464  10868   5016 S  0.3  0.6  12:36.60 AliYunDun
12405 root      10 -10  135464  10868   5016 S  0.3  0.6   4:27.44 AliYunDun
12372 root      10 -10  135464  10868   5016 S  0.0  0.6  17:20.43 AliYunDun
12374 root      10 -10  135464  10868   5016 S  0.0  0.6   2:28.64 AliYunDun
12385 root      10 -10  135464  10868   5016 S  0.0  0.6   4:11.51 AliYunDun
12388 root      10 -10  135464  10868   5016 S  0.0  0.6   0:03.77 AliYunDun
12389 root      10 -10  135464  10868   5016 S  0.0  0.6   0:23.02 AliYunDun
12390 root      10 -10  135464  10868   5016 S  0.0  0.6   0:07.14 AliYunDun
12391 root      10 -10  135464  10868   5016 S  0.0  0.6  17:15.42 AliYunDun
12392 root      10 -10  135464  10868   5016 S  0.0  0.6   9:57.15 AliYunDun
12394 root      10 -10  135464  10868   5016 S  0.0  0.6  11:39.28 AliYunDun
12395 root      10 -10  135464  10868   5016 S  0.0  0.6   0:22.60 AliYunDun
12396 root      10 -10  135464  10868   5016 S  0.0  0.6   1:03.32 AliYunDun
12397 root      10 -10  135464  10868   5016 S  0.0  0.6   0:34.48 AliYunDun
12398 root      10 -10  135464  10868   5016 S  0.0  0.6   3:10.77 AliYunDun
12400 root      10 -10  135464  10868   5016 S  0.0  0.6   0:24.87 AliYunDun
12401 root      10 -10  135464  10868   5016 S  0.0  0.6   0:08.17 AliYunDun
12402 root      10 -10  135464  10868   5016 S  0.0  0.6   0:30.05 AliYunDun
12403 root      10 -10  135464  10868   5016 S  0.0  0.6   4:25.90 AliYunDun
12404 root      10 -10  135464  10868   5016 S  0.0  0.6   8:17.53 AliYunDun