Killing a java zombie process

DotNet picture DotNet · Sep 25, 2012 · Viewed 15.7k times · Source

I am running an experimental java application and every time I kill or stop the application, zombie processes get created. I know zombies are not really an issue as they (supposedly) will not consume resources. However, my RAM free space gets significantly less than it should be. Here is the dump of

ps aux | grep java

3052  8.5  0.0      0     0 ?        Zl   Sep24 127:24 [java] <defunct>
6644  0.9  0.0      0     0 ?        Zl   Sep24  13:20 [java] <defunct>
8325  0.7  0.0      0     0 ?        Zl   Sep24  11:01 [java] <defunct>
8954  0.7  0.0      0     0 ?        Zl   Sep24  11:01 [java] <defunct>
16229  1.3  0.0      0     0 ?        Zl   Sep24  16:57 [java] <defunct>
19222  106  0.0      0     0 ?        Zl   Sep24 1346:37 [java] <defunct>

None of the following works :(

kill -9 PID , kill -1 PID, kill -KILL PID 

I cannot reboot my machine! so I would highly welcome any solutions.

Answer

A.H. picture A.H. · Sep 25, 2012

The wait(2) man page tells you:

A child that terminates, but has not been waited for becomes a "zombie". The kernel maintains a minimal set of information about the zombie process (PID, termination status, resource usage information) in order to allow the parent to later perform a wait to obtain information about the child. As long as a zombie is not removed from the system via a wait, it will consume a slot in the kernel process table, and if this table fills, it will not be possible to create further processes. If a parent process terminates, then its "zombie" children (if any) are adopted by init(8), which automatically performs a wait to remove the zombies.

So you have to look for the parent process IDs of your zombies and kill these. Then init will bury your zombies. For this ps -f or pstree will help you.