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.
Shared Memory
An Example: POSIX Shared Memory
Several IPC mechanisms are available for POSIX systems, including shared memory and message passing. Here, we explore the POSIX API for shared memory.
The program http://siber.cankaya.edu.tr/OperatingSystems/cfiles/code55.c code55.c illustrates the POSIX shared-memory API. This program creates a 4,096-byte shared-memory segment. Once the region of shared memory is attached, the process writes the message Hi There! to shared memory. After outputting the contents of the updated memory, it detaches and removes the shared-memory region.
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 5 processes where the first process is the parent of the second and third ones and the third process is the parent of the fourth and fifth ones. Your program should be capable of;
checking if the processes are forked with success,