Linux – Any issue if Zombie state is not cleared

linuxprocess

I have production unit in which java process has become Zombie and remained there for some time now. If the unit is restarted, then it will be cleared. However, the unit is not restarted and another java process is up and running. Is there any issue if this zombie state remains as it is without clearing it? Will it affect in any way (performance or slowness)?

Best Answer

Zombie process won't have any effect on performance or slowness as Zombie processes don’t use up any system resources.

Note:- Practically, it is still using the PID (which is a limited resource), and the kernel data structures for the process are still allocated. Usually, this won't matter much, but the kernel memory usage can be significant on systems with very limited memory.

Problem caused by zombie process

Each zombie process retains its process ID . Linux systems have a finite number of process IDs – 32767 by default on 32-bit systems.If zombies are accumulating at a very quick rate ,the entire pool of available PIDs will eventually become assigned to zombie processes, preventing other processes from launching.

Note: On 64-bit systems, you can increase the maximum PID, see https://unix.stackexchange.com/a/16884/170373

However, a few zombie processes hanging around are no problem – although they do indicate a bug with their parent process on your system.

Explanation:

When a process dies on Linux, it isn’t all removed from memory immediately — its process descriptor stays in memory.

The process’s status becomes EXIT_ZOMBIE and the process’s parent is notified that its child process has died with the SIGCHLD signal.

The parent process is then supposed to execute the wait() system call to read the dead process’s exit status and other information. This allows the parent process to get information from the dead process. After wait() is called, the zombie process is completely removed from memory.

This normally happens very quickly, so you won’t see zombie processes accumulating on your system. However, if a parent process isn’t programmed properly and never calls wait(), its zombie children will stick around in memory until they’re cleaned up.

Resolution:

You can’t kill zombie processes as you can kill normal processes with the SIGKILL signal — zombie processes are already dead.

One way to kill zombie is by sending the SIGCHLD signal to the parent process. This signal tells the parent process to execute the wait() system call and clean up its zombie children. Send the signal with the kill command, replacing pid in the command below with the parent process’s PID:

kill -s SIGCHLD pid

When the process that created the zombies ends, init inherits the zombie processes and becomes their new parent. (init is the first process started on Linux at boot and is assigned PID 1.)

Note:- From Linux 3.4 onwards processes can issue the prctl() system call with the PR_SET_CHILD_SUBREAPER option, and as a result they, not process #1, will become the parent of their orphaned descendant processes. Refer: https://unix.stackexchange.com/a/177361/5132  

INIT then executes the wait() system call to clean up its zombie children, so init will make short work of the zombies. You can restart the parent process after closing it.

Related Question