LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   An example of fork() and wait() functions (https://www.linuxquestions.org/questions/programming-9/an-example-of-fork-and-wait-functions-487645/)

asdandekar 09-28-2006 04:29 AM

An example of fork() and wait() functions
 
Please tell me how to use fork() and wait() functions to create a child process and transform that process into a zombie state.

scoban 09-28-2006 05:39 AM

Take a look at here:

http://www.cs.cf.ac.uk/Dave/C/node22...00000000000000

pankaj99 09-28-2006 05:55 AM

The link above tells you how to fork() a process.
To create 'zombies' I believe you have to use
signal handlers.
When a child process terminates it send SIGCHLD signal
to its parent process .
If the parent process *ignores* the SIGCHLD signal
the child becomes a zombie.

ciotog 09-29-2006 05:33 PM

To transform the child process into a zombie you just have it call exit(), and have the parent not pay attention to the SIGCHLD signal as pankaj99 said.

I use waitpid(-1, NULL, WNOHANG); in the parent process to clean up any zombie children, since in the program that uses it I don't care when or why the child exited.


All times are GMT -5. The time now is 12:04 AM.