When a child process terminates, an association with its parent survives until the parent in turn either terminates normally or calls wait.
The child process entry in the process table is therefore not freed up immediately.
Although no longer active, the child process is still in the system because its exit code needs to be stored in case the parent subsequently calls wait. It becomes what is known as defunct, or a zombie process.
Call the ps -ux program in another shell after the child has finished but before the parent has finished, we'll see a phrase in the line. (Some systems may say rather than .)
If the parent then terminates abnormally, the child process automatically gets the process with PID 1 (init) as parent.
The child process is now a zombie that is no longer running but has been inherited by init because of the abnormal termination of the parent process.
Understanding system - http://siber.cankaya.edu.tr/OperatingSystems/cfiles/code20.c code20.c .
Try to recognize your ``code20'' and corresponding PID from the output.
Exercises:
Write a program that creates a zombie and then call system to execute the ps command to verify that the process is zombie.
Write a program to create 4 processes where first process is the parent of the second one and the second process is the parent of the third one and the third process is the parent of the fourth one. Your program should be capable of;