A zombie (also called: ghost) process is a terminated process but not waited upon by its parent.
Zombie/ghost processes continue to consume small portion of the operating system’s resources.
Be a responsible parent: if you
fork()
a child process, you must wait()
on the child – even if you don't care about the child's return status.
But what happens if the parent dies before the child? Whenever a process terminates, the kernel walks its children and re-parents them to the init process. (Bonus question: what is the
pid
of init?)
The init process periodically waits on all its children and allows them to exit normally and fully, ensuring zombies don't live for long and, therefore, don't take up valuable OS resources.