Start here
wait. An orphan has lost its parent while still alive, it is reparented, not deleted.Zombies and orphans
On exit, the kernel converts a process to a zombie so the parent can read exit code and resource usage. If the parent never waits, zombies accumulate and can exhaust PID space. If the parent dies first, init (PID 1) or a subreaper adopts orphans and must reap them.
By the end of this page you should be able to
- State what resource a zombie still holds.
- Explain reparenting in one sentence.
- Predict failure mode if PID1 stops reaping children.
Operating systems · Processes
Zombie and orphan processes
Reaping, adoption, and PID 1 duties
TL;DR
A zombie is a terminated child whose exit status has not been consumed, PCB slot remains. An orphan is a live child whose parent died; it is reparented (classically to init) which must reap it. Both are lifecycle bookkeeping, not “malware states.”
Summary
These states show how Unix ties parent/child relationships into resource reclamation. Supervisors (k8s kubelet, systemd) must handle SIGCHLD and wait loops correctly or nodes exhaust PIDs.
Deeper narrative
Zombies hold exit codes for parents; orphans are reparented, not freed. Init or a subreaper must reap to avoid PID exhaustion under fork-heavy workloads (web servers, CI).
Mechanism (step by step)
Exit path
Set zombie state, notify parent with `SIGCHLD`, keep minimal PCB.
wait / waitid
Parent consumes status; kernel frees PID and final structures.
Orphan rule
Living parent gone → reparent to subreaper or PID1.
PID1 duty
Must reap in loop or delegate to threaded reaper, otherwise table fills.
Key insights
Kernel must keep exit code
Init must reap loops
Zombies are not running
Orphans keep running
Did you know?
Common pitfalls
Ignoring SIGCHLD default
If not handled or ignored with correct semantics, zombies accumulate.
Double wait
Multiple threads waiting same child-`waitpid` with specific pid avoids races.
Comparison
Zombie vs orphan
| Zombie | Orphan | |
|---|---|---|
| Alive? | No (terminated) | Yes |
| Parent alive? | Often yes (not waiting) | No (reparented) |
| Primary fix | Parent calls wait / fix signal handler | Init must reap / correct service code |
Glossary
Zombie
Orphan
Subreaper
Interview follow-ups
- How does `PR_SET_CHILD_SUBREAPER` change orphan behavior?
- Can a zombie consume significant RAM?
- What breaks if PID1 stops calling `wait`?
Callouts
Outage pattern
“Cannot fork” on a healthy machine sometimes means zombie table exhaustion, not RAM.
Walkthrough & deep dive
Left: practical “how would I use this?” threads. Right: slower, code-leaning explanations, open one panel at a time so the page does not feel like a wall of sameness.
Walkthrough
Debug script
Deep dive
SIGCHLD handler pattern
Non-blocking wait loop in handler avoids losing events; be careful with async-signal-safe functions only.
Spot zombies
ps -eo pid,ppid,stat,cmd | awk '$3 ~ /Z/ {print}'
Self-check
1A zombie process…
2An orphan is…
3Reaping clears…