linux 8種進(jìn)程狀態(tài)
通過ps aux可以看到進(jìn)程的狀態(tài)。
O:進(jìn)程正在處理器運(yùn)行,這個(gè)狀態(tài)從來沒有見過.
S:休眠狀態(tài)(sleeping)
R:等待運(yùn)行(runable)R Running or runnable (on run queue) 進(jìn)程處于運(yùn)行或就緒狀態(tài)
I:空閑狀態(tài)(idle)
Z:僵尸狀態(tài)(zombie)
T:跟蹤狀態(tài)(Traced)
B:進(jìn)程正在等待更多的內(nèi)存頁
D: 不可中斷的深度睡眠,一般由IO引起,同步IO在做讀或?qū)懖僮鲿r(shí),cpu不能做其它事情,只能等待,這時(shí)進(jìn)程處于這種狀態(tài),如果程序采用異步IO,這種狀態(tài)應(yīng)該就很少見到了
其中就緒狀態(tài)表示進(jìn)程已經(jīng)分配到除CPU以外的資源,等CPU調(diào)度它時(shí)就可以馬上執(zhí)行了。運(yùn)行狀態(tài)就是正在運(yùn)行了,獲得包括CPU在內(nèi)的所有資源。等待狀態(tài)表示因等待某個(gè)事件而沒有被執(zhí)行,這時(shí)候不耗CPU時(shí)間,而這個(gè)時(shí)間有可能是等待IO、申請(qǐng)不到足夠的緩沖區(qū)或者在等待信號(hào)。
在Linux源碼中, 進(jìn)程狀態(tài)的定義在fs/proc/array.c文件中。
/*
* The task state array is a strange "bitmap" of
* reasons to sleep. Thus "running" is zero, and
* you can test for combinations of others with
* simple bit tests.
*/
static const char * const task_state_array[] = {
"R (running)", /* 0 */
"S (sleeping)", /* 1 */
"D (disk sleep)", /* 2 */
"T (stopped)", /* 4 */
"t (tracing stop)", /* 8 */
"X (dead)", /* 16 */
"Z (zombie)", /* 32 */
};
進(jìn)程狀態(tài)轉(zhuǎn)換






