JDK-4523660 : (process) Process.destroy fails to close in/out/err streams causing IOException
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2001-11-06
  • Updated: 2017-10-30
  • Resolved: 2017-10-30
Related Reports
Relates :  
Bug mentioned below exists for all previous JDK releases and current Merlin release.

File handles are not getting freed up when a Process object is destroyed.
User needs to implement a close for each stream. It would be better
if destroy() method could close all streams for a given process.

Please see workaround on how to fix testcase to get around file handle issue.
This needs to be documented for Merlin in some way or fixed in future release.

Testcase below:

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());

We need to close streams only if we have not given them out.

###@###.### 2002-06-24

There may be output from the process stuck in the streams. Changing the behavior at this late stage would be a compatibility issue.

WORK AROUND insert a Runtime.getRuntime().gc(); call after the p.destroy() or p.getOutputStream().close(); p.getInputStream().close(); p.getErrorStream().close();

EVALUATION We need to close streams only if we have not given them out. ###@###.### 2002-06-24