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.
|
|
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. |
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. |