我正在尝试将 Linux 进程状态代码(如ps
)映射到操作系统状态图中的状态,但我似乎无法映射它们。是不是因为 Linux 进程状态不一定与理论上的 OS 状态图匹配?具体地讲,我不确定其中D
/ S
/ T
/I
配合的图中
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)
I Idle kernel thread
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
来自维基百科的操作系统进程状态图:
类似于“停止”是否属于“阻塞”状态?但答案很不完整。
各州(大致)映射如下:
状态 | 意义 |
---|---|
D |
被封锁 |
I |
被封锁 |
R |
Waiting or Running |
S |
Blocked |
T |
Blocked (more or less) |
t |
Blocked (more or less) |
W |
Blocked (obsolete since Linux 1.1.30) |
X |
Terminated |
Z |
Terminated |
The externally visible process state codes in Linux try to pack information that might be interesting for a system administrator into one character, so they also include information why a process is blocked (and thus if it can be unblocked and what may unblock it).
The distinction between "Waiting" and "Running" is blurred, because processes run in such tiny time slices that, for a human sitting in front of the computer, there is not much difference between a process ready to run and a process running.
Also Linux doesn't swap out whole processes but individual memory pages, so you won't find states mapping to "Swapped out and waiting" or "Swapped out and blocked".
State | Meaning |
---|---|
D |
The process is blocked and that state cannot be interrupted (e.g. with kill ). Usually while in this state the kernel is performing I/O on behalf of the process, and the kernel code in question isn't able to handle interruptions. |
I |
The process is a kernel thread that currently has nothing to do and is blocked waiting for new work. This state is technically the same as D (as usually kernel threads aren't interruptible). It was introduced for accounting/cosmetic reasons, because processes in D state are considered contributing to the system load. |
R |
The process is waiting to run or running. These are all processes the scheduler can and will schedule on the available CPUs. Internally the kernel can differentiate between running and waiting processes but this isn't exposed through the process state codes. |
S |
The process is blocked and that state can be interrupted with kill . This state is entered with most system calls that wait for some event (sleep , select , poll , wait , etc.). |
T |
The process is blocked from being scheduled by a signal like SIGSTOP . This state doesn't match perfectly into the theoretical state "Blocked" because the process doesn't wait for an event by itself, but is usually blocked from further running by intervention of another process or the user (Ctrl+Z). |
t |
Similar to above. The process is blocked from being scheduled by a debugger or tracing process, not by itself waiting for an event. |
W |
过时的。该进程被阻塞,等待将内存页从交换区读取到 RAM 中。这段代码一直使用到 Linux v1.1.30。从 v2.3.43 开始,无法再将进程置于此状态,并且从 v2.5.50 开始,对这种状态的每个引用都已删除。 |
X |
进程终止,当前正在从进程列表中删除。您不会经常看到这种状态,因为它只ps 在内核清理另一个 CPU 内核上的进程条目的瞬间运行时才会出现。 |
Z |
进程终止,进程列表中的条目仅存在,以便父进程可以收集退出状态信息。 |
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句