What are the Zombie and the Orphan Processes and how to kill them?

What are the Zombie Processes?

On Unix and Linux systems, the zombie (or defunct) processes are dead processes that still apear in the process table, usually because of bugs and coding errors. A zombie process remains in the operating system and does nothing until the parent process determines that the exit status is no longer needed.

Watch Free Movies

When does a process turn into a zombie?

Normally, when a process finishes execution, it reports the execution status to its parent process. Until the parent process decides that the child processes exit status is not needed anymore, the child process turns into a defunct or zombie process. It does not use resources and it cannot be scheduled for execution. Sometimes the parent process keeps the child in the zombie state to ensure that the future children processes will not receive the same PID.

How to find and kill a zombie process:

You can find the zombie processes with ps aux | grep Z. The processes with Z in the STATE field are zombie processes:

$ ps aux | grep Z

How to kill a zombie process:

To kill a zombie process, find the zombie’s parent PID (PPID) and send him the SIGCHLD (17) signal: kill -17 ppid
I use this command to find a PPID: ps -p PID -o ppid

$  ps -p 20736 -o ppid
$ kill -17 20735

Note: If you kill the parent of a zombie proceess, also the zombie process dies.

What are the Orphan Processes?

An Orphan Process is a process whose parent is dead (terminated). A process with dead parents is adopted by the init process.
When does a process become an orphan process?
Sometimes, when a process crashes, it leaves the children processes alive, transforming them into orphan processes. A user can also create a orphan process, by detaching it from the terminal.

How to find orphaned processes:
This command will not display only the orphaned processes, but all the processes having the PPID 1 (having the init process as it’s parent).

$ ps -elf | awk '{if ($5 == 1){print $4" "$5" "$15}}'
298 1 upstart-udev-bridge
302 1 udevd
438 1 /usr/sbin/sshd

Orphan processes use a lot of resources, so they can be easily found with top or htop. To kill an orphaned process, use kill -9 PID.

Scroll to Top