1. 程式人生 > >LINUX 筆記-top命令

LINUX 筆記-top命令

觀察 狀況 rup 1.5 system and 進程 hugepage 系統

top命令經常用來監控linux的系統狀況,比如cpu、內存的使用。

top - 08:16:55 up 1 day,  1:09,  2 users,  load average: 0.00, 0.01, 0.00
Tasks: 252 total,   1 running, 250 sleeping,   0 stopped,   1 zombie
%Cpu(s):  0.5 us,  0.3 sy,  0.0 ni, 98.6 id,  0.4 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  4025440 total,   858884 free,  1388728 used,  1777828 buff/cache
KiB Swap:  
4192252 total, 4192252 free, 0 used. 2260048 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 20 0 119788 5980 4020 S 0.0 0.1 0:11.81 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.06 kthreadd 4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 6 root 20 0 0 0 0 S 0.0 0.0 0:00.86 ksoftirqd/0 7
root 20 0 0 0 0 S 0.0 0.0 1:16.12 rcu_sched 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root rt 0 0 0 0 S 0.0 0.0 0:00.07 migration/0 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 0:00.29 watchdog/0 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0 13 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/1 14 root rt 0 0 0 0 S 0.0 0.0 0:00.37 watchdog/1 15 root rt 0 0 0 0 S 0.0 0.0 0:00.08 migration/1 16 root 20 0 0 0 0 S 0.0 0.0 0:13.69 ksoftirqd/1 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H 19 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kdevtmpfs 20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns 21 root 20 0 0 0 0 S 0.0 0.0 0:00.16 khungtaskd 22 root 20 0 0 0 0 S 0.0 0.0 0:00.00 oom_reaper 23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback 24 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kcompactd0 25 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd 26 root 39 19 0 0 0 S 0.0 0.0 0:13.78 khugepaged 27 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto 28 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd 29 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset 30 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd 33 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ata_sff 34 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md 35 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 devfreq_wq 36 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 watchdogd 39 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kauditd 40 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kswapd0

第一行:

  系統負載,即任務隊列的平均長度。
  三個數值分別為 1分鐘、5分鐘、15分鐘前到現在的平均值。

第三行:

cpu狀態
  us — 用戶空間占用CPU的百分比。
  sy — 內核空間占用CPU的百分比。
  ni — 改變過優先級的進程占用CPU的百分比
  id — 空閑CPU百分比
  wa — IO等待占用CPU的百分比
  hi — 硬中斷(Hardware IRQ)占用CPU的百分比
  si — 軟中斷(Software Interrupts)占用CPU的百分比

第七行以下:各進程(任務)的狀態監控

PID — 進程id
USER — 進程所有者
PR — 進程優先級
NI — nice值。負值表示高優先級,正值表示低優先級
VIRT — 進程使用的虛擬內存總量,單位kb。VIRT=SWAP+RES
RES — 進程使用的、未被換出的物理內存大小,單位kb。RES=CODE+DATA
SHR — 共享內存大小,單位kb
S — 進程狀態。D=不可中斷的睡眠狀態 R=運行 S=睡眠 T=跟蹤/停止 Z=僵屍進程
%CPU — 上次更新到現在的CPU時間占用百分比
%MEM — 進程使用的物理內存百分比
TIME+ — 進程使用的CPU時間總計,單位1/100秒
COMMAND — 進程名稱(命令名/命令行)

常用參數:

  在鍵盤上輸入大寫字母M 以達到以內存占用率大小順序排列。另外輸入大寫字母P可以按CPU使用率排序。

  每兩秒鐘更新一次 top ,觀察整體信息,-d參數:top -d 2

  假設 9999 是一個已經存在的 PID ,用top命令僅觀察指定pid的程序的-p參數用法:top -d 2 -p 9999

LINUX 筆記-top命令