JDK-4191034 : (process) java.lang.Process.destroy() fails to free up file handles.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.2.0,1.2.1
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_2.6
  • CPU: x86,sparc
  • Submitted: 1998-11-18
  • Updated: 2001-11-05
  • Resolved: 2001-11-05
Related Reports
Relates :  

Name: tb29552			Date: 11/18/98


This is a bug that was evidently introduced in
JDK 1.2 RC1.

I have an application that repeatedly invokes a program
by creating a Process object with the Runtime.exec
method. The process is destroyed when completed.
However, since the introduction of JDK 1.2 RC1, this
only works a few times before a bogus IOException
occurs. Evidently, system file handles are not getting
freed up when a Process object is destroyed.

Here is a test case the demonstrates the problem.
(By the way, I'm on a Solaris 5.5.1/x86 platform).

import java.io.IOException;
class FHT {
    public static void main(String args[]) {
        for (int i = 0; i < 4000; i++) {
            try {
                Process p = Runtime.getRuntime().exec("/bin/echo hello");
            catch(IOException x) {
                System.err.println("Bogus IOException after " + i +
                                   " invocations: " + x.getMessage());

(Review ID: 42890)

EVALUATION Help on this bug from Fred Oliver, This is not a bug, rather it is a problem in testcase that they are not monitoring the output of the new process. Consequently, the streams used for communication between the parent (old) and child (new) processes are never closed. Since the streams never get closed explicitly, the file descriptors don't get closed until the stream object finalizers are run. Making a call to runtime.gc(); will close the file handles but no guarentees. but making p.getOutputStream().close(); p.getInputStream().close(); p.getErrorStream().close(); Should close all the open handles.

WORK AROUND Name: tb29552 Date: 11/18/98 I tried explicitly closing the input, output, and err streams of the Process. But it only delays the problem to later. Evidently, there are internal file handles not getting freed. ====================================================================== put a Runtime.getRuntime().gc(); after p.destroy() will make the problem disappear. ###@###.### 2001-11-05 p.getOutputStream().close(); p.getInputStream().close(); p.getErrorStream().close();