Skip to content

Troubleshooting guide

Zombie processes on Linux: what they are and how to clear them

A zombie has already exited. Only its exit status remains, waiting for its parent to collect it, so you cannot kill it. Fix the parent.

3 min read10 sectionsUpdated

On this page

Key points

  • A zombie uses a process-table slot, not memory.
  • kill -9 has no effect on it.
  • The parent is the real bug.
  • Containers without an init commonly accumulate them.

What a zombie is

When a process exits, the kernel retains a small record until its parent calls wait(). In between, the process shows as Z or <defunct>. A few that come and go are normal. Thousands that persist mean the parent never reaps its children, and eventually the PID limit will stop new processes from starting.

Common causes

  • An application that spawns child processes and never waits for them.
  • A container whose PID 1 is your app, which does not reap orphaned children the way init does.
  • Headless browsers or shell scripts launched in large numbers.
  • A hung parent.

Diagnose it

Count them, and then identify the parents.

bash
# How many?
ps -eo stat | grep -c '^Z'

# Parents with the most zombie children
ps -eo ppid,stat,comm | awk '$2 ~ /^Z/ {print $1}' | sort | uniq -c | sort -rn | head

# What is that parent?
ps -o pid,etime,cmd -p PARENT_PID

# PID limit and current usage
cat /proc/sys/kernel/pid_max; ps -eLf | wc -l

Fixes

Fix the parent so it waits for children, or sets its child handler correctly. As an immediate measure, restart the parent. Its zombies pass to init, which reaps them at once. In containers, add an init: docker run --init, or shareProcessNamespace or tini in the image, which is especially important for images that start Chromium. Sending SIGCHLD to the parent occasionally helps if its handler works.

Telling zombies from stuck processes

Do not confuse state Z with state D. A D-state process is alive, blocked inside the kernel, usually on storage, and it counts towards load average. A zombie is finished and consumes no CPU at all. If ps shows <defunct> beside the name, it is a zombie, and looking at its stack is pointless. The information you need lives in the parent. Note the PPID, then inspect why that program is not calling wait, which is usually a missing child handler in a long-running service.

Catch it automatically

Chart total processes and zombies per host in infrastructure monitoring, and alert on PID usage. In Kubernetes, the pids limit prevents one bad pod from starving the node.

Frequently asked questions

Can I kill a zombie process?

No, because it is already dead. Make the parent reap it, or restart the parent.

Do zombies use memory?

Almost none. The danger is using up process IDs.

Why do zombies appear in containers?

PID 1 in a container is often an application that does not reap orphaned processes. Use an init.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.