Orphan and Zombie Processes
What you'll learn: You'll discover what happens when parent processes die early or fail to clean up after their children.
When Parents Abandon Their Children
In a typical process lifecycle, a parent creates a child using fork(), and later calls wait() to collect the child's exit status when it terminates. But sometimes things don't go as planned.
Orphan Processes
An orphan process occurs when a parent process terminates before its child does. The child is now "orphaned" — it still exists and runs normally, but its biological parent is gone.
What happens? The operating system doesn't let processes become truly parentless. The orphaned child is automatically adopted by the init process (PID 1 on Unix/Linux systems). The init process becomes the new parent and will eventually reap the orphan when it terminates.
Think of it like this: If your parents disappear, social services (the OS) reassigns you to a foster parent (init) who will take responsibility for you.
Zombie Processes
A zombie process (also called a "defunct" process) is the opposite problem: a child process has finished executing and called exit(), but its parent hasn't yet called wait() to read its exit status.
The process is dead but not fully cleaned up. Its PCB remains in the process table, holding the exit code and resource usage statistics until the parent collects them.
The analogy: It's like a finished exam sitting on the teacher's desk — the test is complete, but it occupies space until the teacher records the grade and files it away.
Why it matters: Zombies consume process table entries. If a parent creates many children but never reaps them, zombie processes accumulate, potentially exhausting system resources.
Key Takeaway: Orphans occur when parents die early (OS reassigns them to init); zombies occur when children die but parents don't reap them (they linger until collected).