The various statuses for a process are:
1. Running (R)
2. Orphan (O)
3. Sleeping (S)
4. Zombie (Z)
The snapshot (Fig 11 above) displays the output of the ‘ps –el’ command.
As mentioned earlier, synchronisation between processes is very important. And there is always a need to prevent a process becoming an orphan or a zombie. Linux provides an important system call – wait() (Fig 12 below)– that will help in synchronising the processes. This system call will also ensure that a process will not become an orphan or a zombie.
Whenever we make a call to the wait() function, it results in a number of things happening. A check is first made to see if the parent process has any children. If it does not, then a -1 value is returned by wait(). If the parent process has a child that has terminated (a zombie), that child’s PID is returned and its entry is removed from the process table. However, if the parent process has a child or children that have not terminated, it (the parent process) is suspended till it receives a signal. This signal is received as soon as the child dies.
Let us consider an example to understand the concept of process synchronisation:
pid = fork();
if (pid == 0)