Zombie Processes in Linux

What is a zombie?

Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel.

Causes of Zombie Processes:

When a subprocess exits, its parent is supposed to use the "wait" system call and collect the process's exit information. The subprocess exists as a zombie process until this happens, which is usually immediately. However, if the parent process isn't programmed properly or has a bug and never calls "wait," the zombie process remains, eternally waiting for its information to be collected by its parent.

Killing Zombie Processes:

Zombie processes persist until their parent process ends, at which point they are adopted by the "init" system process and shortly cleaned up. However, there's no way to get rid of a zombie process without ending its parent process. If you have a lot of zombie processes, close and restart the parent process or service. Init adopts and cleans up the orphaned zombie processes. If you can't close the parent process, don't worry, zombies won't affect the performance of your computer unless a very large amount are present. However, bear in mind that, if a process is creating a lot of zombies, it has a programming bug or error in its code and isn't working correctly.
Viewing Zombie Processes

The Execute the "top" command in a Terminal window. The top command shows the number of zombie processes at the upper-right side of its output, in the Tasks: row.

You can also list running processes by executing the "ps aux" command. Zombie processes have a "z" listed in their Stat column in the output of the 'ps aux" command.

Risks of Zombie Processes:

While zombie processes aren't a problem in and of themselves and take up very little resources, there is one concern. Linux systems have a maximum amount of processes and thus process ID numbers. If a computer has enough zombie processes, the maximum amount is reached and new processes can't be launched.

The maximum amount of processes can be listed by typing the "cat /proc/sys/kernel/pid_max" in a Terminal window and is usually 32768. Thus, zombie processes are usually not a concern.

However, if the parent process creating zombie processes is server software that isn't written properly, a large amount of zombies could be created under load. Or, zombies could gradually accumulate over long periods of time until the maximum process limit is reached.

Comments

Popular posts from this blog

yum failed 6 times. Cannot continue!

Resolved: DOCKER: Error response from daemon: Could not attach to network / rpc error: code = 7 desc = network not manually attachable.

unexpectedly shrunk window (repaired) in dmesg log - TCP Peer