How to solve Zombie and Orphan Process Problems ?

Hey guys i need help on this problem ..
How to solve zombie and orphan process problems ?
Please explain with an example...
If you are using fork() to create the processes then you
need to do a waitpid() to reap the return codes from the
children.

A synchronous example is:

pid_t pid = fork();
if( pid == 0 ) {
// Child context here
} else if( pid > 0 ) {
// Parent context here
int status = 0;
waitpid( pid, &status, 0 );
}

waitpid won't return until the child exits. When the child
exits, status will be filled out with the return code from
the child process.
Topic archived. No new replies allowed.