Skip to content
We areTOP 1%

What are zombie and orphan processes?

MediumConceptProcesses & Threads
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A zombie process is a child that has finished (called exit()) but whose parent has not yet read its exit status with wait(). It no longer runs or holds memory, but its entry stays in the process table. An orphan is a child whose parent ended first; on Linux it is adopted by init/systemd (PID 1) or by a designated "subreaper" process, which collects its status when it exits.

  • Zombies exist because the kernel must keep the exit status until the parent asks for it.
  • One zombie is harmless, but a parent that never calls wait() can pile up thousands of them and exhaust the available process IDs.
  • Fixes: call wait() or waitpid(), handle the SIGCHLD signal, or end the parent so that its zombies are adopted and cleaned up.
  • An orphan is not a problem in itself; it keeps running normally.

Example:

if (fork() == 0) exit(0);   // child ends at once
sleep(60);                  // parent never calls wait()

For 60 seconds, ps shows the child in state Z, marked <defunct>. If instead the parent exited while the child was still running, the child would become an orphan and its parent PID would change to that of the adopting process.

More in Processes & Threads

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account