大寫字母:
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct (”zombie”) process, terminated but not reaped by its parent.
小寫字母及其它符號:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group
Linux上進程有5種狀態:
1. 運行(正在運行或在運行隊列中等待)
2. 中斷(休眠中, 受阻, 在等待某個條件的形成或接受到信號)
3. 不可中斷(收到信號不喚醒和不可運行, 進程必須等待直到有中斷發生)
4. 僵死(進程已終止, 但進程描述符存在, 直到父進程調用wait4()系統調用後釋放)
5. 停止(進程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU信號後停止運行運行)
ps工具標識進程的5種狀態碼:
D 不可中斷 uninterruptible sleep (usually IO)
R 運行 runnable (on run queue)
S 中斷 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
注: 其它狀態還包括W(無駐留頁), <(高優先級進程), N(低優先級進程), L(內存鎖頁).
使用ps格式輸出來查看進程狀態:
ps -eo user,stat..,cmd
user 用戶名
uid 用戶號
pid 進程號
ppid 父進程號
size 內存大小, Kbytes字節.
vsize 總虛擬內存大小, bytes字節(包含code+data+stack)
share 總共享頁數
nice 進程優先級(缺省為0, 最大為-20)
priority(pri) 內核調度優先級
pmem 進程分享的物理內存數的百分比
trs 程序執行代碼駐留大小
rss 進程使用的總物理內存數, Kbytes字節
time 進程執行起到現在總的CPU暫用時間
stat 進程狀態
cmd(args) 執行命令的簡單格式
例子:
查看當前系統進程的uid,pid,stat,pri, 以uid號排序.
ps -eo pid,stat,pri,uid –sort uid
查看當前系統進程的user,pid,stat,rss,args, 以rss排序.
ps -eo user,pid,stat,rss,args –sort rss
參考:
1. Linux Kernel Development Second Edition -
Ch3-1 Process Descriptor and the Task Structure
2. Linux man page for ps.