๐ง Zombie Process Guide (BlackCairn)¶
A practical guide to identifying, understanding, and cleaning up zombie processes on your Linux systems and Docker containers.
๐ง What is a Zombie Process?¶
A zombie process is a process that has:
- Finished execution
- But still exists in the process table
- Because its parent has not collected its exit status
Think of it as a process that has diedโฆ but its paperwork hasnโt been filed.
๐ How to Identify Zombie Processes¶
Basic check¶
ps aux | grep Z
Cleaner output¶
ps -eo pid,ppid,state,cmd | awk '$3 ~ /Z/'
Example output¶
8763 2445 Z [wget] <defunct>
๐งพ Understanding the Output¶
| Column | Meaning |
|---|---|
| PID | Zombie process ID |
| PPID | Parent process ID |
| Z | Zombie state |
| CMD | Original command |
โ ๏ธ The parent (PPID) is the key. Zombies cannot be killed directly.
๐ต๏ธ Investigate the Parent Process¶
ps -fp <PPID>
Example:
ps -fp 2445
๐ณ If Using Docker (BlackCairn Reality)¶
Find the container:
docker inspect --format '{{.Name}}' <container-id>
Then inspect it:
docker exec -it <container-name> ps -ef
๐งน How to Clean Up Zombies¶
โ Best Option: Restart the Parent¶
Docker¶
docker restart <container-name>
System service¶
sudo systemctl restart <service>
โ ๏ธ Alternative: Signal the Parent¶
kill -SIGCHLD <PPID>
May or may not work.
๐ซ Do NOT do this¶
kill -9 <zombie-pid>
Zombies are already dead. This does nothing.
๐งฎ Count Zombie Processes¶
ps -eo state | grep -c Z
โ ๏ธ When to Worry¶
| Scenario | Meaning |
|---|---|
| 1โ2 zombies | Normal, harmless |
| Growing count | Parent process issue |
| Hundreds | Broken service or container |
๐ ๏ธ Preventing Zombies (Docker Best Practice)¶
Add an init process to containers:
services:
your-service:
image: your-image
init: true
This ensures child processes are properly reaped.
๐งช Common Causes¶
- Healthchecks using
wgetorcurl - Poorly written shell scripts
- Node/Next.js apps spawning child processes
- Containers without an init process
๐ BlackCairn Example (Real Case)¶
- Zombie:
[wget] <defunct> - Parent:
next-server - Container:
blackcairn-portal - Cause: Docker healthcheck using
wget - Fix: Added
init: trueto Compose
๐งญ Quick Troubleshooting Flow¶
- Find zombie
- Identify PPID
- Check parent process
- Determine if Docker or system service
- Restart parent
- Add
init: trueif container-based - Recheck
๐งน Maintenance Tip¶
Run occasionally:
ps -eo pid,ppid,state,cmd | awk '$3 ~ /Z/'
If empty โ all clear
๐ Final Thoughts¶
Zombie processes are not dangerous on their own.
They are symptoms, not problems.
Fix the parent, and the undead disappear.
โ๏ธ Motto¶
"You donโt kill the zombieโฆ you fix what refused to bury it."