Glossary/When something goes wrong
Zombie process
Also: defunct process
Quick answer
A zombie process is a process that has finished running but still has an entry in the process table, because its parent process has not yet collected its exit status. It uses no CPU and holds almost no memory.
When a process ends, the system keeps a small record so the parent can find out how it exited. Normally the parent reads that record right away and the entry disappears. If the parent never does, the finished process stays listed as a zombie.
A few zombies are harmless. A steadily growing number points to a bug in the parent program.
How to find zombie processes on a Mac
In Terminal, run ps -axo pid,ppid,stat,comm | awk '$3 ~ /^Z/'. Each line is a zombie, and the PPID column shows the parent process responsible for it.
How to get rid of a zombie process
You cannot kill a zombie, because it has already exited. The fix is the parent. Quit or restart the parent app, and the zombie is handed to launchd, which cleans it up.
Do not quit launchd or other system processes to clear zombies. If the parent is a system process, a restart of the Mac clears them.
How to find the parent of a zombie
In the full command column of ps, a zombie is shown as <defunct>, because its program has already exited. The parent is the process to deal with.
- Run
ps -axo pid,ppid,stat,comm | awk '$3 ~ /^Z/'to list zombies. The Z in the STAT column marks a zombie. - Note the number in the PPID column.
- Run
ps -p <PPID> -o pid,user,commandto see which program is the parent. - In Activity Monitor, choose View > All Processes, Hierarchically to see the same parent and child tree.
- Deal with the parent. If it is an app you opened, quit and reopen it. If it is a shell or a script in Terminal, close that window or stop the script. If it is a system process, restart the Mac.
Normal vs worrying
A parent program collects a child's exit status with the wait family of system calls. A program that starts child processes but never waits for them leaves zombies behind. That is a bug in the parent, and only its developer can fix it for good.
Seeing a zombie for a moment is normal. It exists between the time a process exits and the time its parent reads its exit status, which is usually very short.
It is worth a look when the same parent keeps many zombies around, or when their number keeps growing over hours. To count them, run ps -axo stat | grep -c '^Z'. To see the process limits on your Mac, run sysctl kern.maxproc kern.maxprocperuid.
Zombie, orphan, and hung processes are different
These three terms are often mixed up, and each one needs a different fix.
- A zombie has finished running. Only its entry in the process table is left.
- An orphan is still running, but its parent has exited. macOS hands it to launchd, PID 1, which becomes its new parent.
- A hung process is still running but stuck, often shown as Not Responding in Activity Monitor. Unlike a zombie, it can be quit or force quit.
What not to do
Zombies are harmless in small numbers, so there is no reason to take risks to clear them.
- Do not run
kill -9on the zombie's PID. It has already exited, so the signal has no effect. - Do not quit launchd or other system processes to clear zombies. A restart does the same thing safely.
- Do not quit the parent without checking what it is. If it is an app with open documents, save your work first.
Questions people ask
What is a zombie process on a Mac?
It is a process that has finished but is still listed because its parent has not collected its exit status. It uses no CPU.
How do I kill a zombie process?
You cannot kill it directly. Quit or restart its parent process, shown in the PPID column of `ps`, and the zombie goes away.
Are zombie processes harmful?
A few are not. Each one takes a slot in the process table, so a large and growing number can eventually cause problems and points to a buggy parent program.
Why can kill -9 not remove a zombie process?
A zombie is not running, so there is nothing for the signal to stop. Only its parent collecting its exit status, or the parent exiting, removes it.
Does restarting the Mac remove zombie processes?
Yes. A restart ends every process, including zombies and their parents.
Are zombie processes a sign of malware?
No. They are a normal part of how Unix processes exit. Many zombies from one parent usually mean that program has a bug.
Related
Looking for something better than Activity Monitor? See the best Activity Monitor alternatives for Mac, or browse every term in the glossary.