previous | start

Zombies

If a process (the parent) calls fork() to create a process (the child), the parent doesn't automatically wait for the child to finish. The parent must call waitpid to do wait.

So if waitpid is not called, which process finishes first?

Either one could finish first.

If the parent finishes first, the child becomes an orphan and is adopted by a system process called init whose pid is 1.

If the child finishes first, it becomes a zombie.

The child is mostly dead, but the parent might call waitpid. So it's termination information must be retained until the parent either terminates or calls waitpid.

A server process typically creates a child process, but doesn't wait for it to terminate. Instead it tries to create more children.

Problem: This can lead to a lot of zombies. Solution should involve only calling waitpid (to finally get rid of child process when the child terminates.

How does the parent know when the child terminates?



previous | start