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
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.
# 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 -lFixes
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.
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.
Related reading
- Linux OOM killer: why it killed your process: Understand the Linux OOM killer: read the kernel log to see what was killed and why, how oom_score works, and how to protect critical services from it.
- High CPU usage on a Linux server: find the cause: Diagnose high CPU on a Linux server: read top, load, steal and iowait, find the busy process and thread, profile it and spot throttling.
- Exit code 137: what it means in Docker and Kubernetes: Exit code 137 means a container received SIGKILL. Learn to tell memory limits from slow shutdowns and manual kills, with Docker and Kubernetes commands.
- High iowait on Linux: how to find the cause: Diagnose high iowait on Linux with iostat and iotop: read await and %util correctly, find the process doing the I/O, and fix slow queries and swap.
- Incident response plan: a template for software teams: An incident response plan for software teams: detection, triage, roles, communication, mitigation and postmortems, with a template you can adapt.
- No space left on device on Linux: how to fix it: Fix "No space left on device" on Linux: find large files, deleted files still open by processes, and inode exhaustion, with safe commands for a production host.
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.