19

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)?

Ravi
  • 759

2 Answers2

23

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Arushix
  • 1,290
  • Is there any chance where wait() itself fails? – Ravi Jun 26 '18 at 10:09
  • I dont know what do you mean it wait() fails, wait() is a system call which blocks the calling process from executing until one of its child terminates or a signal is recieved, once the child exits, execution of calling process is resumed – Arushix Jun 26 '18 at 10:14
  • I meant- what if the 'SIGCHLD' is not received indefinitely? – Ravi Jun 26 '18 at 10:26
  • In that case, zombie processes will remain there, as the parent wont be notified of the exit status of the child process – Arushix Jun 26 '18 at 10:31
  • 3
    On 64-bit systems, you can increase the maximum PID, see https://unix.stackexchange.com/a/16884/170373 – ilkkachu Jun 26 '18 at 10:33
  • The part about ignoring SIGCHLD is wrong. – JdeBP Jun 26 '18 at 11:29
  • 1
    The part about reparenting is wrong, too. https://unix.stackexchange.com/a/177361/5132 Ironically, making programs subreapers that do not expect to be is an easy way to cause long-term zombie processes. – JdeBP Jun 26 '18 at 11:34
  • 2
    The parent will already have received a SIGCHLD when the process that is now a zombie died. – Ángel Jun 26 '18 at 19:53
  • On Linux, if the parent is ignoring SIGCHLD, it won't generate zombies. – Ángel Jun 26 '18 at 19:53
  • Where's the quoted text from? – cat Jun 26 '18 at 22:13
  • 2
    Strictly speaking it's not correct to say that it uses no resources. It is still using the PID (which is a limited resources), 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. – Austin Hemmelgarn Jun 27 '18 at 01:18
  • Thanks everyone for the suggestions and corrections, I have gone through the links and edited my answer to include the corrections – Arushix Jun 27 '18 at 04:26
6

Mostly, zombies are not a big issue. They are a 'dead'-ish process, which takes no CPU time, and any allocated memory should have been freed by the process before dying. The only resource they actually take is an entry in your process list. Depending on your system, you can have a maximum allowed number of threads, and having zombies can make you reach this limit faster for no reason.

However : Zombies usually appear because of bad/buggy code, where the programmer forgot to check the states of its child processes. This can be intentional, but often it is not. Bad/buggy code will often also handle memory in a bad special way, and Not free some allocated resources. If this is the case, these resources will stay allocated for the zombie, until it is fully terminated.

Edit : If the process is a java program, not freed memory should not be an issue, as the java garbage collector takes care of everything.

Vince
  • 131