JDK-6594674 : (process) Process.waitFor returns but process remains as zombie
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: x86
  • Submitted: 2007-08-20
  • Updated: 2011-02-16
  • Resolved: 2007-08-28
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot (TM) Server VM (build 1.6.0_01-b06, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux crazyhost 2.6.9-22.ELsmp #1 SMP Mon Sep 18:32:14 EDT 2005 2005 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
We have a deployment system where many workers are running on different machines. To ease our maintenance, we have developed a small service which, using JMX, allows for remote starting and stopping of these domains.

Each domain is started by using the Runtime.exec method in a different thread, which also waits for the process to finish using the Process.waitFor method.

When a domain is stopped, we tried using two options:
1. Runtime.exec which calls a "kill -9 PID"
2. A more cross-platform approach of using a native method wrapped with a Java method.

Both options produced the bug, but currently we use the latter.

  To describe the bug: When killing more than one process at the same time (using an iterator over a list of PID numbers), all threads waiting on the Process.waitFor finish their work (the waitFor method returns). However, some processes are marked as zombies - and worse, the "jps" tool shows them with no indication of their zombie status.

Since we use jps to tell which of our workers are running, this is very problematic.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a service which runs multiple Java processes, these processes using multiple resources such as files and sockets. The processes are waitFor'ed using a different thread for each process object.

Destroy all these processes from the same service which ran them, using JNI or another Runtime.exec, but do that in iteration over all PIDs (PIDs can be obtained using jps).

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All processes are dead and "ps" and "jps" should show none of them (only the original service should be running).
ACTUAL -
Some of the processes (other than the management service) are still showing, and if looking through "ps" they have the "<defunct>" mark on them, marking them as zombies.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
No exception or error is shown.

REPRODUCIBILITY :
This bug can be reproduced often.

---------- BEGIN SOURCE ----------
Hard to produce a short source code for this, as this is a complex application with many different elements.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None yet. At the moment, we kill the management service from time to time to allow zombies to be retrieved by the "init" process, and then restart the management service.

Comments
EVALUATION No word from the submitter, but since this is so likely to be a duplicate, I am closing it now as such.
28-08-2007

EVALUATION This certainly looks like a duplicate of 6474073: (process) Runtime.exec() creates zombies (sol) but to be sure, the submitter should try to see whether the problem goes away in JDK 6u2 or JDK 7, where the fix has been integrated. If so, we can close this as a duplicate.
20-08-2007