Rapid commands to detect defunct "Z" processes and act on them. 05.12.2025 | reading time: 2 min A "zombie" is a defunct child process that has exited but still occupies a PID entry because its parent did not reap it; find them quickly to avoid PID-table clutter or service surprises. Reproduce and detect Create a simple C program that forks and lets the parent sleep so the child becomes a zombie, then detect it with `ps`; try this exactly: ``` cat > zombie.c <<'EOF' #include <unistd.h> #include <sys/types.h> #include <stdlib.h> int main(){ pid_t pid = fork(); if(pid==0){ _exit(0); } else { sleep(60); } return 0; } EOF gcc -O2 zombie.c -o zombie ./zombie & ps aux | awk '$8 ~ /Z/ {print $2, $8, $11}' ``` The sample output will show the child's PID with STAT "Z", for example "12345 Z ./zombie". Quick fixes to try First inspect the zombie's parent with `ps -o pid,ppid,stat,cmd -p <child_pid>` and then either signal the parent to reap children with `kill -s SIGCHLD <parent_pid>` or restart the parent service; if the parent is hung and not suitable to restart, terminating the parent lets init or systemd adopt and reap the zombie. Command variations that help Other quick detections: use `ps -eo pid,ppid,stat,cmd | awk '$3 ~ /Z/'` to view columns directly, or scan `/proc` with `grep -H "State" /proc/*/status | grep "Z"` to see kernel state strings; `top` and `htop` also show STAT with a "Z" marker for visual hunts. When many zombies appear A flood of defunct processes signals a parenting bug — escalate to debug the service: examine code paths that omit `wait()` or `waitpid()`, use `pstree -p` to trace parentage, and prefer fixing the program instead of repeatedly killing processes. Finish line You now have reproducible steps to spot and handle zombie processes fast; keep practicing these commands and consider formal study to deepen skills, for example by preparing for CompTIA Linux+ or LPIC-1 with intensive exam training at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. processes troubleshooting utilities