🧠 What is a Zombie Process?

A Zombie Process is a terminated (dead) process that still has an entry in the process table, because its parent hasn’t yet read its exit status.

In simpler terms:

  • It’s dead, but not fully cleaned up.

  • The OS keeps its PID and exit code in the process table so the parent can collect it.


🔁 When Does It Happen?

A process becomes a zombie after it:

  1. Finishes execution (calls exit() or returns from main)

  2. But the parent has not yet called wait() or waitpid()

So, it’s waiting to be “reaped” by its parent.


🧩 Visual Lifecycle

[Running] → exit() → [Zombie] → (wait() called) → [Removed from process table]

⚠️ Why Do Zombies Matter?

RiskDescription
🧠 Process Table PollutionEvery zombie consumes a PID/entry in process table
🔁 Too Many ZombiesCan exhaust available PIDs, preventing new processes
🐞 Bug SignUsually indicates bad parent process design

📚 Real-World Example (Linux)

if (fork() == 0) {
    exit(0);  // Child exits
} else {
    sleep(10);  // Parent sleeps, doesn't call wait()
    // Child becomes zombie during this time
}

During the sleep, ps aux will show:

Z+  ...  ./a.out  <defunct>

Here, <defunct> means the process is a zombie.


🧠 How Are Zombies Cleaned Up?

  • Parent process must call wait() or waitpid() to collect the child’s exit status.

  • If the parent itself dies, the zombie gets adopted by init (PID 1).

    • init will automatically reap any orphaned zombie.

⚙️ Real-World Analogy

Imagine a child finishes a school exam and is waiting at the desk with a paper in hand (exit code).
Until the teacher (parent) collects the paper (calls wait()), the child is sitting idle (zombie) and occupying a chair (process table entry).


🧠 Interview-Ready Definition:

A Zombie Process is a terminated process that has not been fully cleaned up by the OS because its parent has not yet collected its termination status using wait(). It remains in the process table, consuming resources, and can cause system issues if left unchecked.