Hey guys i need help on this problem ..
How to solve zombie and orphan process problems ?
Please explain with an example...
when you fork a new process, it's parents responsibility to query the exit status of the child. This exit status can be queried by system calls like 'wait','waitpid' etc
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <sys/wait.h>
-
main()
-
{
-
int i, j, status;
-
i = fork();
-
if (i > 0) //parent
-
{
-
j = wait(&status);
-
}
-
else //child
-
{
-
sleep(1000);
-
exit(0);
-
}
-
}
-
In this code parent will wait till child finishes.
So in short..parent must issue a wait call to avoid a zombie processes.