March 2, 2007 Leave a comment
This morning I got to thinking. What happens if parents die before their kids? The world could be flooded with zombies.
Some background. Unix allows a child to get the PID of its parent or the execution state of its children. For example, a parent can spawn a child to complete some process, and then wait to check when the child has terminated.Â If the child is dead, it’s termination code will tell the parent whether or not the task was completed succesfully.
So Anyway, Unix kernels can’t discard data in the process descriptor fields right after a process terminates. They can only kill themselves completely after their parent has issued a wait()-like call (seen whether their task was completed).Â This is why zombies were introduced: although the process is dead, it must live until the parent is notified of it’s death.
So if a parent dies to leave orphaned children, the world could theoretically be flooded with these zombies, since there are no parents to issue wait()-like system calls. This problem is solved by forcing all orphans to become children of Init. In this way, Init will destroy zombies while checking for the termination of one of its legitimate children through wait()-like calls.
The release_task() function detaches the last data structures from the descriptor table – or “blows their brains out” if you will.
Obviously, everything I’m saying is not about processes, but about real zombies and an unsung hero named init.