December 4, 2026

Zombie Processes on Linux: Why kill -9 Does Nothing to a Defunct Process

A server rack with one grey frozen indicator among living green lights

A process marked Z in ps was sent SIGKILL, the one signal no program can catch or ignore. A fifth of a second later it was still there, still marked Z, still holding its process ID. Nothing had gone wrong. A zombie is a process that has already finished; there is nothing left to kill. Every result in this post comes from processes created and inspected on a Linux machine for the purpose, and the output shown is what ps printed.

Video: Jacob Sorber on YouTube

What a zombie is

A finished process waiting for its parent

When a process exits on Linux, it does not vanish at once. The kernel keeps a small record so the parent can find out how it ended. The wait(2) manual page puts it this way: a child that terminates but has not been waited for becomes a “zombie”. The kernel keeps a minimal set of information about it, its PID, termination status and resource usage, so that the parent can later perform a wait and collect that information.

The ps manual describes the Z state code as a defunct (“zombie”) process, terminated but not reaped by its parent. “Reaped” is the word for the parent’s wait() call. Until it happens, the entry stays.

Making one on purpose

A short Python program forked a child that exited immediately with status 3, then deliberately did not wait for it. Half a second later:

  PID  PPID STAT COMMAND
 3053  3052 Z    python3

The parent, 3052, was alive and well. The child, 3053, was dead in every sense that matters except bookkeeping.

Four wooden clothes hangers

Why kill -9 does nothing

There is no process left to stop

The test then sent SIGKILL to the zombie and checked again:

 PID STAT
 3053 Z

Unchanged. A signal is a request delivered to running code, and a zombie runs no code. Its memory, open files and threads were released when it exited; only the process-table entry remains. The earlier post on kill signals covers what SIGKILL does to a living process, and none of that applies here.

What does remove it

The parent calling wait(). When the test program finally called waitpid() on the child, it got back the PID and a status word that decoded to exit code 3, the value the child had exited with. A follow-up ps for PID 3053 returned only its header line. The entry was gone.

While the entry exists, its PID stays taken. No new process can be handed 3053 until the zombie is reaped, which is what keeps a late wait() from collecting the status of some unrelated process that happened to reuse the number.

That exit code is the whole reason zombies exist. A shell needs $?; a supervisor needs to know whether a worker crashed or finished. The kernel holds the answer until someone asks.

When zombies become a problem

One is harmless; thousands are not

A single zombie costs almost nothing. The wait(2) manual names the real risk: as long as a zombie is not removed, it will consume a slot in the kernel process table, and if that table fills, no further processes can be created. On the test machine, /proc/sys/kernel/pid_max read 32,768. A parent that leaks one zombie per request would hit that on a busy day.

The pattern to watch for is not one Z line but a count that keeps growing under the same parent. In the test, a program that forked five children and never waited showed exactly that shape:

$ ps -eo pid,ppid,stat,comm | awk '$3 ~ /^Z/'
 3062  3060 Z    python3
 3063  3060 Z    python3
 3064  3060 Z    python3
 3065  3060 Z    python3
 3066  3060 Z    python3

Five zombies, one parent. The PPID column is the one that matters, because it names the program with the bug.

White envelope on a black background

Getting rid of zombies

Fix or restart the parent

Because only the parent can reap its children, the fix is always about the parent. If the program can be told to reap (some daemons do this on SIGCHLD or a reload), that works. Otherwise, ending the parent works too, and the manual explains why: when a parent terminates, its zombie children are adopted by init(1), or by the nearest “subreaper” process, and init automatically performs a wait to remove them. The ps manual says the same in older words: defunct processes will be destroyed by init if the parent exits.

The test killed the parent of the five zombies with kill -9. Half a second later all five were still listed, now orphaned. Three seconds later the count was zero: the machine’s PID 1 had adopted and reaped them. Adoption is not instant, but it is reliable when PID 1 does its job.

Ignoring SIGCHLD

A program that never needs its children’s exit status can opt out of zombies entirely. The wait(2) manual says POSIX.1-2001 specifies that if SIGCHLD is set to SIG_IGN, children that terminate do not become zombies. The test repeated the fork with signal.signal(signal.SIGCHLD, signal.SIG_IGN) first. The ps lookup for the child returned only its header: no zombie, no entry at all.

The trade-off is that the parent can no longer learn how its children exited. For a fire-and-forget helper that is fine. For anything that has to report failures, it is not.

Orphans and subreapers

Two different words

An orphan is a running process whose parent has exited. A zombie is a finished process whose parent has not yet waited. The two meet when an orphan finishes: whoever adopted it has to do the reaping.

Watching adoption happen

A Python script started a shell, which launched a background sleep 1 and exited at once. Reading /proc/<pid>/status for the orphaned sleep showed PPid of 1: the machine’s init had adopted it. When it finished a second later, its status file read State: Z (zombie) until init got to it.

The same test was run again after the script marked itself a child subreaper with prctl(PR_SET_CHILD_SUBREAPER, 1). The manual page for that option says a subreaper fulfills the role of init(1) for its descendant processes: an orphan is reparented to the nearest still-living ancestor subreaper instead of to PID 1. That is what happened. The orphaned sleep showed the script’s own PID as its parent, became a zombie when it finished, and disappeared the moment the script called waitpid() on it.

Subreapers are how service managers and container runtimes keep track of everything a service spawns, even grandchildren whose parents have already exited. A process that sets the flag also takes on the duty that comes with it: reap what it adopts, or collect zombies of its own.

Shipping containers at a port

Zombies in containers

When PID 1 is the application

The reaping rule assumes PID 1 is an init system that waits on whatever it adopts. Inside a container, PID 1 is often the application itself, and most applications were never written to reap children they did not start.

The test reproduced this with a PID namespace, the same mechanism containers use. A Python script ran as PID 1, started a shell, and the shell launched three short background jobs and exited at once, leaving them orphaned. A second and a half later:

    PID    PPID STAT COMMAND
      1       0 S    python3 /tmp/pid1.py
      3       1 Z    [sh] <defunct>
      4       1 Z    [sh] <defunct>
      5       1 Z    [sh] <defunct>

Three zombies, all adopted by PID 1, none reaped, because the Python script had no idea it was supposed to. The same sequence with bash as PID 1 ended with no zombies in the list: bash reaps the children it collects.

docker run –init

Docker’s answer is a small init process. The docker run reference describes --init as running an init inside the container that forwards signals and reaps processes. It goes on to say the default init is a docker-init binary included in the default installation and backed by tini. Kubernetes and Compose setups have their own equivalents. Any container whose main process spawns helpers, shells out to scripts, or runs something like a headless browser is a candidate.

Finding zombies on a machine

The commands

Counting zombies:

$ ps -eo stat | grep -c '^Z'

Listing them with their parents:

$ ps -eo pid,ppid,stat,comm | awk '$3 ~ /^Z/'

top reports the count in its second header line without any filtering. With the five-zombie test program running, top -bn1 printed a tasks line ending in 5 zombie. That number is the cheapest early warning there is: if it is above zero on every check and climbing, a parent somewhere is not reaping.

/proc/<pid>/status shows the same thing with a State: line reading Z (zombie), as it did in the tests above, plus a PPid: line naming the parent. The parent is where to look, every time. A zombie also holds no open files, so it does not count toward the descriptor limits covered in the post on too many open files; the cost is the process slot and nothing else.

A zombie that has been sitting there for a week under a long-lived daemon is a bug report waiting to be filed against that daemon. A burst of them that clears in a few seconds is a system working as designed.

Sources

  • PR_SET_CHILD_SUBREAPER(2const), Linux manual page (man7.org): https://man7.org/linux/man-pages/man2/PR_SET_CHILD_SUBREAPER.2const.html
  • wait(2), Linux manual page (man7.org): https://man7.org/linux/man-pages/man2/wait.2.html
  • ps(1), Linux manual page (man7.org): https://man7.org/linux/man-pages/man1/ps.1.html
  • docker container run, Docker Docs: https://docs.docker.com/reference/cli/docker/container/run/

672 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *