我正在尝试创建一个僵尸进程[重复]

问题描述 投票:1回答:1

这个问题在这里已有答案:

我试图通过了解在线解决方案来创建僵尸进程

但我仍然无法使用以下代码找到任何僵尸进程

我不知道我的代码出了什么问题

我正在尝试pstree -ptop命令找到我的僵尸进程,但我找不到任何

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>


int main(int argc, char const *argv[])
{
    pid_t childPID;

    childPID = fork();

    if(childPID < 0)
    {
        printf("child Process creation failed\n");
    }
    else if(childPID == 0)
    {

        printf("I am child Process.My pid is: %d\n", getpid());

        exit(0);

        sleep(100);
    }
    else
    {
        sleep(10);


        printf("I am parent process.my pid: %d\n", getpid());
        printf("My child process is: %d\n",childPID);
    }

    return 0;
}

enter image description here

enter image description here

c linux operating-system fork zombie-process
1个回答
3
投票

好吧,我可以看到父母仍在运行时的僵尸进程

enter image description here

但是当父母去世时,两个过程都会消失。我的猜测是,一旦父进程死亡,init(或任何与pid 1运行的进程)waitpids为僵尸从而将其从进程列表中删除。

另见Create zombie process

© www.soinside.com 2019 - 2024. All rights reserved.