【问题标题】:How does a zombie process manifest itself?僵尸进程是如何表现出来的?
【发布时间】:2011-11-04 06:34:22
【问题描述】:

kill -s SIGCHLD
以上是杀死任何僵尸进程的代码,但我的问题是:
僵尸进程有什么表现形式吗?

【问题讨论】:

标签: unix operating-system


【解决方案1】:

steenhulthin 是正确的,但在它被移动之前,有人不妨在这里回答它。在子进程终止与父进程调用wait() 函数之一以获取其退出状态之间存在僵尸进程。

一个简单的例子:

/* Simple example that creates a zombie process. */

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(void)
{
    pid_t cpid;
    char s[4];
    int status;

    cpid = fork();

    if (cpid == -1) {
        puts("Whoops, no child process, bye.");
        return 1;
    }

    if (cpid == 0) {
        puts("Child process says 'goodbye cruel world.'");
        return 0;
    }

    puts("Parent process now cruelly lets its child exist as\n"
         "a zombie until the user presses enter.\n"
         "Run 'ps aux | grep mkzombie' in another window to\n"
         "see the zombie.");

    fgets(s, sizeof(s), stdin);
    wait(&status);
    return 0;
}

【讨论】:

  • +1 表示“残忍地让它的孩子存在......”:) 和一个很好的答案。
猜你喜欢
  • 2011-01-26
  • 2019-02-05
  • 2011-03-14
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 2014-06-19
  • 2014-09-30
相关资源
最近更新 更多