Linux是一個多用戶,多任務的 系統,能夠同時運行多個用戶的多個程序,就必然會產生不少的進程,而每一個進程會有不一樣的狀態。 在下文將對進程的R、S、D、T、Z、X 六種狀態作個說明。node
PROCESS STATE CODESlinux
Here are thedifferent values that the s, stat and state output specifiers (header"STAT" or "S") will display to describe the state of aprocess.session
D Uninterruptiblesleep (usually IO)oracle
R Runningor runnable (on run queue)app
S Interruptiblesleep (waiting for an event to complete)異步
T Stopped,either by a job control signal or because it is being traced.spa
W paging(not valid since the 2.6.xx kernel)orm
X dead(should never be seen)blog
Z Defunct("zombie") process, terminated but not進程
reapedby its parent.
For BSD formatsand when the stat keyword is used,additional characters may be displayed:
< high-priority(not nice to other users)
N low-priority(nice to other users)
L haspages locked into memory (for real-time and custom IO)
s isa session leader
l ismulti-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group
一. 查看進程的狀態
1.1 使用PS命令
[root@localhost]# ps -a -opid,ppid,stat,command -u oracle
PID PPID STAT COMMAND
637 1Ss oracleXEZF (LOCAL=NO)
729 1Ss oracleXEZF (LOCAL=NO)
1144 1103 S+ top
1230 1Ss oracleXEZF (LOCAL=NO)
1289 1145 S+ vmstat 10
1699 1Ss oracleXEZF (LOCAL=NO)
1827 1294 R+ ps -a -opid,ppid,stat,command -u oracle
3410 1Ss ora_pmon_XEZF
3412 1Ss ora_psp0_XEZF
3414 1Ss ora_mman_XEZF
3416 1Ss ora_dbw0_XEZF
3488 1 Ssl /home/oracle_app/bin/tnslsnr LISTENER -inherit
11167 1Ss oracleXEZF (LOCAL=NO)
19323 1Ss oracleXEZF (LOCAL=NO)
用ps 的 – l 選項,得 到更詳細的進程信息:
(1)F(Flag):一系列數字的和,表示進程的當前狀態。這些數字的含義爲:
00:若單獨顯示,表示此進程已被終止。
01:進程是核心進程的一部分,常駐於系統主存。如:sched,vhand,bdflush。
02:Parent is tracing process.
04 :Tracing parent's signal has stopped the process; the parentis waiting ( ptrace(S)).
10:進程在優先級低於或等於25時,進入休眠狀態,並且不能用信號 喚醒,例如在等待一個inode被建立時。
20:進程被裝入主存(primary memory)
40:進程被鎖在主存,在事務完成前不能被置換。
(2) 進程狀態:S(state)
O:進程正在處理器運行,這個狀態歷來木見過.
S:休眠狀態(sleeping)
R:等待運行(runable)R Running or runnable (on runqueue) 進程處於運行或就緒狀態
I:空閒狀態(idle)
T:跟蹤狀態(Traced)
B:進程正在等待更多的內存頁
D:不可中斷的深度睡眠,通常由IO引發,同步IO在作讀或寫操做時,cpu不能作其它事情,只能等待,這時進程處於這種狀態,若是程序採用異步IO,這種狀態應該就不多見到了
(3)C(cpuusage):cpu利 用率的估算值
1.2 使用Top命令中的S 字段
piduser pr ni virt res shrs %cpu%mem time+ command
11423oracle 16 0 627m170m168mR 32 9.0 4110:21oracle
3416oracle 15 0 650m158m138mS 0 8.4 0:07.12oracle
637oracle 15 0 629m 76m 73mS 0 4.0 0:04.31oracle