What is a Zombie Process?
Learn what a zombie process is, how it forms, and how wait() reaps it — with examples and operating systems interview questions.
Expected Interview Answer
A zombie process is a process that has finished execution but still has an entry in the process table because its parent has not yet read its exit status.
When a process terminates, the kernel keeps a minimal record — the exit code, PID, and resource usage — so the parent can retrieve it via wait() or waitpid(). Until the parent calls wait, the child remains a zombie: it holds no memory or open files, just a process table slot. If the parent never calls wait, the zombie lingers until the parent itself exits, at which point init (or the nearest surviving ancestor) adopts and reaps it. A small number of zombies is harmless, but a parent that spawns children without ever reaping them can exhaust the process table, a bug distinct from an orphan process.
- Preserves exit status until the parent explicitly collects it
- Uses negligible resources — just a process table entry
- Automatically reaped by init if the parent exits first
- Diagnosable with ps by the Z state and defunct label
AI Mentor Explanation
A zombie process is like a batter who has been given out but is still listed on the scoreboard until the scorer formally records the dismissal. The player has stopped playing — they hold no bat or gear — but their entry stays on the board taking up a line until someone writes down how they got out. If the scorer never records it, that stale line sits there forever, exactly like an unreaped zombie clogging the process table.
Step-by-Step Explanation
Step 1
Process exits
The child finishes execution and the kernel frees its memory and file descriptors.
Step 2
Exit status kept
The kernel retains a small process table entry holding the PID and exit status.
Step 3
Parent calls wait
The parent calls wait() or waitpid() to retrieve the exit status, at which point the entry is removed.
Step 4
Reparenting fallback
If the parent exits without waiting, init (or the nearest ancestor) adopts and reaps any lingering zombies.
What Interviewer Expects
- A precise definition: terminated process, unread exit status
- That a zombie holds no memory or files, just a table entry
- The role of wait()/waitpid() in reaping
- The difference between a zombie and an orphan process
Common Mistakes
- Confusing a zombie process with an orphan process
- Thinking a zombie still consumes CPU or memory
- Believing zombies can be killed with SIGKILL (they cannot — they are already dead)
- Not mentioning that init reaps zombies of exited parents
Best Answer (HR Friendly)
“A zombie process is a process that has already finished running but its parent has not yet checked its final result, so a small placeholder entry stays in the system. It does not use any real resources, just a slot in the process table, and it disappears once the parent reads that final status.”
Code Example
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void) {
pid_t pid = fork();
if (pid == 0) {
_exit(0); /* child exits immediately -> becomes a zombie */
} else {
sleep(5); /* during this window "ps" shows a Z (zombie) */
int status;
waitpid(pid, &status, 0); /* reaping: removes the zombie entry */
printf("Child reaped, exit status: %d\n", WEXITSTATUS(status));
}
return 0;
}Follow-up Questions
- What is the difference between a zombie and an orphan process?
- How does init reap zombies?
- What problems can too many zombie processes cause?
- How does SIGCHLD relate to reaping zombies?
MCQ Practice
1. What state is a zombie process in?
A zombie has finished execution; only its process table entry remains until the parent reads its exit status.
2. Which system call removes a zombie process entry?
The parent calling wait() or waitpid() retrieves the exit status and clears the zombie’s table entry.
3. What happens to zombie children if their parent exits without waiting?
init (or the nearest surviving ancestor) adopts orphaned zombies and reaps them.
Flash Cards
What is a zombie process? — A terminated process whose exit status has not yet been read by its parent.
What resources does a zombie hold? — None besides a small process table entry — no memory, no open files.
How is a zombie reaped? — The parent calls wait() or waitpid() to read its exit status.
What if the parent never waits? — init adopts and reaps the zombie once the original parent exits.