JDK-4210128 : Running a process from JVM hangs JVM and Process . both.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-02-09
  • Updated: 1999-02-12
  • Resolved: 1999-02-12
Related Reports
Relates :  
Description

Name: dbT83986			Date: 02/09/99


When a process (a.exe) is executed, if the process
writes more than 488 bytes of data on it's STDOUT
and we then call the waitFor( ) method of the Process
class to wait for completion of a.exe , both 
the processes hangs.  Strange enough , if in Java
we don't wait for process completion , (mask 
call to waitFor( ) method), then the execution is 
succeeded.  Or if, in a.exe, we only write 488
bytes or less then the waitFor() method works without
hanging .


To reproduce the problem 

Step 1:

Compile the follwing file a.c into a binary a.exe :
//////
#include<stdio.h>

main()
{
        char buf[500];

/*
        // Works
        memset(buf,'\0',500);
        memset(buf,'p',488);
        fprintf(stdout,"%s",buf);
*/
        // dosen't Works
        memset(buf,'\0',500);
        memset(buf,'p',489);
        fprintf(stdout,"%s",buf);
}

/////////////

Step 2:

Compile the following Java program (within a directory test) execute it.
///////////
package test;

import java.io.*;
import java.lang.*;

/**
 * Class for testing
 */
public class Test {
    public static void main(String[]args) {
	InputStream input;
	BufferedReader buf;
	String str;
	Process process;
	Runtime runtimeContext;
	try {
		runtimeContext = Runtime.getRuntime();
		process = runtimeContext.exec("a");
		process.waitFor();
		input = process.getInputStream();
		buf = new BufferedReader(new InputStreamReader(input));
		while((str = buf.readLine()) != null) {

			System.out.println(str);
		}
	
	}
	catch(IOException e) {}
	catch(InterruptedException e) {};
    }
}

/////////////////////////

Step 3:

Run java test.Test to execute Java program and exec
a.exe through JVM.
(Review ID: 40393)
======================================================================

Comments
EVALUATION User error. The main program waits for the subprocess to terminate before it attempts to read its output. If a small amount of output is written, it is stored in the pipe, and the subprocess can terminate, allowing the data in the pipe to be read and printed. If the pipe fills, however, the subprocess blocks. There is then a deadlock, because the subprocess cannot terminate until someone empties the pipe, but this cannot happen unless the process terminates so the waitFor can return. william.maddox@Eng 1999-02-11
11-02-1999