ps中的進程狀態碼
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped by job control signal
t stopped by debugger during the tracing
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
For BSD formats and 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 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
使用kill命令發送信號
查看可用的信號值
kill -l
ps中的加號
- is in the foreground process group
表示進程在前臺進程組中。
例如:
./a.out &
./b.out
huangch+ 190640 99.2 0.0 4216 648 pts/23 R 11:57 0:18 ./a.out
huangch+ 190646 100 0.0 4216 780 pts/23 R+ 11:57 0:05 ./b.out
a.out在後臺運行,而b.out在前臺運行。
內核中的運行狀態
TASK_RUNNING - R
正在運行 或者
已經達到可以運行的狀態,被放入到了運行隊列中,但是還沒有開始運行。
TASK_INTERRUPTIBLE - S
可中斷的睡眠狀態
等待某種事情發生(比如等待socket連接,等待信號量等),而被掛起。
進程的task_struct被放入對應事件的等待隊列中,當這些事件發生時,對應的等待隊列中的一個或多個進程將會被喚醒。
TASK_UNINTERRUPTIBLE - D
不可中斷的睡眠狀態
與 TASK_INTERRUPTIBLE 類似,進程處於睡眠狀態,但是此時進程是不可被中斷的。
不可被中斷是指,該進程不響應異步信號。(硬件中斷仍然有效)
該狀態的意義:內核的某些流程是不可以被打斷的,如果響應異步信號,程序的執行流程就會被插入一段處理異步信號的流程(插入的流程可能只在內核態,也可能在用戶態),於是原有的流程就被打斷了。
當進程與某些硬件交互時(例如進程通過read系統調用對設備文件進行讀操作),可能需要 TASK_UNINTERRUPTIBLE 進行保護,防止交互被打斷,導致設備陷入不可控的狀態。
TASK_STOPPED - T
TASK_TRACED - t
被追蹤狀態,例如使用gdb對進程進行調試,就進入了該狀態。
TASK_DEAD - Z
殭屍進程
進程佔用的所有資源都被回收