简体   繁体   中英

Can't create zombie process

在此处输入图片说明

I'm trying to create a zombie process in C using this:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>

void main()
{
        int pid;
        pid=fork(); /* Duplicate */
        if (pid!=0) /* Branch based on return value from fork() */
        {
                while (1) /* never terminate, and never execute a wait()*/
                sleep(1000);
        }
        else
        {
                exit(42); /* Exit with a silly number */
        }
}

Problem is I only know how to check if a zombie process exists only in bash. So I used the Bash on windows feature available in windows 10. I created an executable file for the above code and ran it in background And checked for a zombie process but couldn't find it. I repeated the same steps in an Ubuntu running PC and it worked. What am I doing wrong?

Windows does not have zombie processes.

Zombies are a peculiarity of the Unix process model -- when a process exits (in UNIX) its exit status isn't sent anywhere. Instead, it just sits around until some other process queries the exit status. The zombie process state allows for this -- after a process exits, it remains a zombie until someone (anyone) queries its exit status.

On Windows, on the other hand, when a process is created with CreateProcess, you specify where the exit status info should be sent when it exits (generally back to its parent, but could be elsewhere). So when a process exits, the data is sent there immediately with no intervention from anywhere. There's nothing and no place for other processes to query for exit status.

If you are using a UNIX emulator (such as cygwin) on Windows, then you may get zombies of a form -- generally the emulator will have a data structure tracking extra UNIX-style process information somewhere, and that data structure will likely contain a place to hold exit status where it can be queried after the process has exited, just like a zombie.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM