Zombie vs Defunct进程?

时间:2017-12-26 10:44:51

标签: linux process zombie-process

僵尸和失效进程之间有区别吗?我找到了维基百科的文章,其中写的是这两个是相同的。在这种情况下,为什么需要为同一过程提供2个不同的术语:

https://en.wikipedia.org/wiki/Zombie_process

3 个答案:

答案 0 :(得分:7)

对于Linux"已解散"和"僵尸"过程是一样的。

来自man ps

  

标记为<defunct>的进程是死进程(所谓的&#34;僵尸&#34;),因为他们的父进程没有正确销毁它们。如果父进程退出,这些进程将被init(8)销毁。

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

答案 1 :(得分:1)

正如Achal所说,ps添加了已失效的文件。严格来说,它们不是一回事。

例如,下表中只有tid 10941是僵尸。 其他线程位于状态D中,而不是Z中。

$ grep prometheus foo/bar/sos_commands/process/ps_-elfL
4 Z root      10941  10920  10941  0    6  80   0 -      0 exit   Mar14 ?  00:11:41 [prometheus] <defunct>
1 D root      10941  10920  11010  0    6  80   0 - 621811 wait_o Mar14 ?  00:11:08 [prometheus] <defunct>
1 D root      10941  10920  11025  0    6  80   0 - 621811 wait_o Mar14 ?  00:08:13 [prometheus] <defunct>
1 D root      10941  10920  11057  0    6  80   0 - 621811 wait_o Mar14 ?  00:11:12 [prometheus] <defunct>
1 D root      10941  10920  11060  0    6  80   0 - 621811 wait_o Mar14 ?  00:11:42 [prometheus] <defunct>
1 D root      10941  10920  11298  0    6  80   0 - 621811 wait_o Mar14 ?  00:11:05 [prometheus] <defunct>

答案 2 :(得分:0)

Zombiedefunct都相同。 ZOMBIEstate of the process中的一个,而没有defunct状态,您可以从内核源代码中看到它。

enum proc_state {
    UNUSED,   /*** processes in initial state **/
    EMBRYO, 
    SLEEPING,
    RUNNABLE, 
    RUNNING, 
    ZOMBIE   /** processes in final state **/
};

僵尸状态表示它已退出但尚未清理的位置

您可以打开proc(1)的手册页,并查看此/proc/[pid]/stat有关该过程的状态信息。这由ps(1)使用。