Monitoring shows hundreds of zombie processes on a host. How do you detect and report them in a script?
BeginnerScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → Zombies (Z state) are finished children whose parent has not called wait(). They use no CPU or memory, only PID slots, but they point to a buggy parent.
What I'd do →
ps -eo stat=,ppid= | awk '$1 ~ /^Z/ {z[$2]++} END {for (p in z) print p, z[p]}' |
while read -r ppid count; do
echo "WARN $count zombies under ppid $ppid ($(ps -o comm= -p "$ppid"))"
done
- You cannot kill a zombie; fix or restart the parent, after which init reaps them.
- In containers, add an init (
docker run --init,tini) when the main process does not reap children.
Why → Reporting the parent tells you what to fix; counting zombies alone does not.
Interview tip → Say "kill the parent, not the zombie".
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateA developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?Advanced