进程状态

最后更新于:2022-04-02 04:03:09

[TOC] ## 进程状态 进程状态的定义在[fs/proc/array.c](https://github.com/torvalds/linux/blob/b6da0076bab5a12afb19312ffee41c95490af2a0/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 */ }; ``` ### 进程状态转换 ![](https://tobegit3hub1.gitbooks.io/understanding-linux-processes/content/process_basic/image/status_transform.svg) 如: 就绪状态的进程只要等到CPU调度它时就马上转为运行状态,一旦它需要的IO操作还没有返回时,进程状态也就转换成等待状态 ### 查看状态 通过 `ps aux` 查看 - O:进程正在处理器运行,这个状态从来没有见过. - S:休眠状态(sleeping) - R:等待运行(runable)R Running or runnable (on run queue) 进程处于运行或就绪状态 - I:空闲状态(idle) - Z:僵尸状态(zombie) - T:跟踪状态(Traced) - B:进程正在等待更多的内存页 - D: 不可中断的深度睡眠,一般由IO引起,同步IO在做读或写操作时,cpu不能做其它事情,只能等待,这时进程处于这种状态,如果程序采用异步IO,这种状态应该就很少见到了
';