ps指令:
ps - report a snapshot of the currentprocesses.
ps [options]:
選項有三種風格:
1 UNIX options, which may be grouped and mustbe preceded by a dash.
2 BSD options, which may be grouped and must not be used with a dash.
3 GNU long options, which are preceded by two dashes.
啟動程序的方式:
系統啟動過程中自動啟動:與終端無關的程序;
使用者通過終端啟動:與終端相關的程序;
選項:
a:所有與終端相關的程序;
x:所有與終端無關的程序;
u:以使用者為中心組織程序狀态資訊顯示;
常用組合之一:aux
[root@localhost ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.7 59776 7712 ? Ss 1月01 0:02 /usr/lib/systemd/system
root 2 0.0 0.0 0 0 ? S 1月01 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S 1月01 0:00 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< 1月01 0:00 [kworker/0:0H]
root 6 0.0 0.0 0 0 ? S 1月01 0:00 [kworker/u256:0]
root 7 0.0 0.0 0 0 ? S 1月01 0:00 [migration/0]
root 8 0.0 0.0 0 0 ? S 1月01 0:00 [rcu_bh]
root 9 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/0]
root 10 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/1]
root 11 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/2]
root 12 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/3]
root 13 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/4]
root 14 0.0 0.0 0 0 ? S 1月01 0:00 [rcuob/5]
VSZ:虛拟記憶體集;
RSS:常駐記憶體集; TTY:終端ID;
STAT:程序狀态,如下:
R:正在運作中(running)
S:可中斷睡眠(interruptablesleeping)
D:不可中斷睡眠(uninterruptablesleeping)
T:停止狀态(Stopped)
Z:僵死狀态(zombie)
+:前台程序
l:多線程程序
N:低優先級程序
<:高優先級程序
s:存在子程序的父程序
START:啟動程序的時間
TIME:程序消耗CPU的時間
COMMAND指令的名稱和參數
例: 1. 可以用 | 管道和 more 連接配接起來分頁檢視
指令:
ps aux | more
2. 把所有程序顯示出來,并輸出到ps001.txt檔案
指令:
ps aux > ps1.txt
-e:顯示所有程序
-f:顯示完整格式的程序資訊
常用組合之二:-ef
[root@localhost ~]# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 1月01 ? 00:00:02 /usr/lib/systemd/systemd --switched-root --sy
root 2 0 0 1月01 ? 00:00:00 [kthreadd]
root 3 2 0 1月01 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 1月01 ? 00:00:00 [kworker/0:0H]
root 6 2 0 1月01 ? 00:00:00 [kworker/u256:0]
root 7 2 0 1月01 ? 00:00:00 [migration/0]
root 8 2 0 1月01 ? 00:00:00 [rcu_bh]
root 9 2 0 1月01 ? 00:00:00 [rcuob/0]
root 10 2 0 1月01 ? 00:00:00 [rcuob/1]
root 11 2 0 1月01 ? 00:00:00 [rcuob/2]
root 12 2 0 1月01 ? 00:00:00 [rcuob/3]
root 13 2 0 1月01 ? 00:00:00 [rcuob/4]
root 14 2 0 1月01 ? 00:00:00 [rcuob/5]
root 15 2 0 1月01 ? 00:00:00 [rcuob/6]
root 16 2 0 1月01 ? 00:00:00 [rcuob/7]
root 17 2 0 1月01 ? 00:00:00 [rcuob/8]
root 18 2 0 1月01 ? 00:00:00 [rcuob/9]
root 19 2 0 1月01 ? 00:00:00 [rcuob/10]
-F:顯示完整格式的程序資訊;
C: cpuutilization
PSR:運作于哪顆CPU之上
-H:以層級結構顯示程序的相關資訊;
常用組合之三:-eFH
[root@localhost ~]# ps -eFH
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
root 2 0 0 0 0 0 1月01 ? 00:00:00 [kthreadd]
root 3 2 0 0 0 0 1月01 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 0 0 0 1月01 ? 00:00:00 [kworker/0:0H]
root 6 2 0 0 0 0 1月01 ? 00:00:00 [kworker/u256:0]
root 7 2 0 0 0 0 1月01 ? 00:00:00 [migration/0]
root 8 2 0 0 0 0 1月01 ? 00:00:00 [rcu_bh]
root 9 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/0]
root 10 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/1]
root 11 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/2]
root 12 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/3]
root 13 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/4]
root 14 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/5]
root 15 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/6]
root 16 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/7]
root 17 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/8]
root 18 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/9]
root 19 2 0 0 0 0 1月01 ? 00:00:00 [rcuob/10]
常用組合之四:-eo, axo
用來輸出指定的字段;
o field1, field2,...:自定義要顯示的字段清單,以逗号分隔;
常用的field:pid, ni,pri, psr, pcpu, stat, comm, tty, ppid, rtprio
ni:nice值;
priority:priority, 優先級;
rtprio:real timepriority,實時優先
例: ps axo pid,ni,session,priority,comm
[root@localhost tmp]# ps axo pid,ni,session,priority,comm
PID NI SESS PRI COMMAND
1 0 1 20 systemd
2 0 0 20 kthreadd
3 0 0 20 ksoftirqd/0
5 -20 0 0 kworker/0:0H
6 0 0 20 kworker/u256:0
7 - 0 -100 migration/0
8 0 0 20 rcu_bh
9 0 0 20 rcuob/0
10 0 0 20 rcuob/1
dstat指令:性能檢測工具
預設選項:-c(cpu),-d(disk),-n(net),-g(page),-y(system)
[root@localhost tmp]# dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
0 0 100 0 0 0|6399B 801B| 0 0 | 0 0 | 23 28
0 0 100 0 0 0| 0 0 | 152B 826B| 0 0 | 24 24
0 0 100 0 0 0| 0 0 | 60B 346B| 0 0 | 29 38
0 0 100 0 0 0| 0 0 | 60B 346B| 0 0 | 19 19
0 1 100 0 0 0| 0 0 | 60B 346B| 0 0 | 17 19
0 0 100 0 0 0| 0 0 | 60B 346B| 0 0 | 18 20
常用選項:
-c, --cpu:顯示cpu相關資訊;
-C #,#,...,total
-d, --disk:顯示磁盤的相關資訊
-D sda,sdb,...,total
-g:顯示page相關的速率資料;
-m:Memory的相關統計資料
-n:Interface的相關統計資料;
-p:顯示process的相關統計資料;
-r:顯示io請求的相關的統計資料;
-s:顯示swapped的相關統計資料;
--tcp:顯示常用的TCP統計
--udp:顯示監聽的UDP接口及其目前用量的一些動态資料
--raw:顯示raw的統計資料
--socket:顯示網絡統計資料
--ipc:報告IPC消息隊列和信号量的使用情況
--top-cpu:顯示最占用CPU的程序;
--top-io:最占用io的程序;
--top-mem:最占用記憶體的程序;
--top-lantency:延遲最大的程序;
top指令:
top指令用來動态監控系統處理器的狀态;
[root@localhost tmp]# top
top - 03:11:55 up 7:08, 3 users, load average: 0.00, 0.01, 0.05
Tasks: 366 total, 1 running, 365 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 1003184 total, 620060 free, 155640 used, 227484 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 650604 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2939 root 20 0 135212 4876 3688 S 0.3 0.5 0:00.47 sshd
1 root 20 0 59776 7712 2640 S 0.0 0.8 0:02.17 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.06 kthreadd
1. 第一行是任務隊列資訊,同 uptime指令:顯示系統時間、運作時長及平均負載;
過去1分鐘、5分鐘和15分鐘的平均負載;等待運作的程序隊列的長度;
2. 第二、三行為程序和CPU的資訊
3. 第四五行為記憶體資訊。
程序資訊:
PR:優先級
NI:nice值,負值表示高優先級,正值表示低優先級
VIRT:程序使用的虛拟記憶體總量
RES:程序使用的、未被換出的實體記憶體大小
SHR:共享記憶體大小
排序:
P:以占據CPU百分比排序;
M:以占據記憶體百分比排序;
T:累積占用CPU時間排序;
首部資訊:
uptime資訊:l指令
tasks及cpu資訊:t指令
記憶體資訊:m指令
退出指令:q
修改重新整理時間間隔:s
終止指定的程序:k
選項:
-d #:指定重新整理時間間隔,預設為3秒;
-b:以批次方式顯示;
-n #:顯示多少批次;
[root@localhost tmp]# top -d 1 -n 3 -b
htop指令:
類似于 top 指令,但可以讓你在垂直和水準方向上滾動,是以你可以看到系統上運作的所有程序,以及他們完整的指令行
選項:
-d #:指定延遲時間間隔;例如,htop -d 100指令會使輸出在1秒後才會重新整理(參數機關是10微秒)。
-u UserName:僅顯示指定使用者的程序;例htop -u gadoop指令會隻顯示出使用者名為 hadoop的相關程序。
-s COLUME:以指定字段進行排序;例htop -s PID指令會按PID列的大小排序顯示。
子指令:
l:顯示標明的程序打開的檔案清單;
s:跟蹤標明的程序的系統調用;
t:以層級關系顯示各程序狀态;
a:将標明的程序綁定至某指定的CPU核心;

通過F1[help]來切換至幫助頁面:
可以使用F5來檢視程序的樹狀圖: