A Zombie process is a process that has completed execution, but still has an entry in the process table (the parent hasn't read its exit code, or in other words, it hasn't been "reaped").
An Orphan process is a process whose parent has finished, though it remains running itself (its parent has "passed away" but it is still "alive"). in this case, init
will adopt it and will wait for it.
So consider this:
int main(int argv, char *argc[]) {
pid_t p=fork();
if (p<0) {
perror("fork");
}
// child
if (p==0) {
exit(2);
}
// parent sleeps for 2 seconds
sleep(2);
return 1;
}
The child process being created here will be a zombie for 2 seconds, but what will be its status when the parent finishes? Orphan-zombie?
What happens to its entry in the process table?
Are "orphan-zombies" (such as the above) also adopted by init
and being reaped by it?