Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4763397

(process) Subprocess hangs if parent does not read its output

XMLWordPrintable



      Name: rmT116609 Date: 10/15/2002


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


      FULL OPERATING SYSTEM VERSION :
      RedHat Linux 7.1 (Seawolf)
      glibc-2.2.2-10

      A DESCRIPTION OF THE PROBLEM :
      A Java process which is launched from another Java 1.4.1
      Class has an output buffer (filled via System.out.println)
      of only 4096 bytes. If it has more than 4096 bytes the
      process hangs / deadlocks.
      In Java 1.4.0 This doesn't occur.

      REGRESSION. Last worked in version 1.4

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Launch a java process from a Java class in Java 1.4.1
      2. In the launched process write (using System.out.println)
      4097 bytes.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected results (as in 1.4.0): The launched process will
      end normally.
      Actual results: The launched process hangs and has to be
      killed.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      1. This is the first class, the one which launches the process.

      import java.io.*;
      public class ProcTest
      {
          public static void main(String[] args)
          {
              try
              {
                  
                   String l_aCommand[] = {
                                          "/usr/java/j2sdk1.4.1/bin/java", "-cp",
                                          ".",
                                          "DummyProcess"};
                                                       
                  Process p = Runtime.getRuntime().exec(l_aCommand);
                  p.waitFor();
                  System.out.println(" Process returned " + p.exitValue() );
              }
              catch (Throwable e)
              {
                  e.printStackTrace();
              }
          }
      }



      2. This is the process class, which is launced by the above class.

      public class DummyProcess
      {
          public static void main(String[] args)
          {
              
              for (int i = 0 ; i < 4097 ; i++ )
              {
                  System.out.print("c");
                  System.out.flush();
              }
              System.exit(0);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Workaround - Be sure to clean the Process InputStream
      buffer. Two main ways to do that:
      1. Direct the Process's OutputStream to a file or another
      device by writing (in the Process's Java code) something
      like:

      FileOutputStream fos = new FileOutputStream("/tmp/out.out");
      FileOutputStream ferr = new FileOutputStrea("/tmp/out.err");
      System.setOut(new PrintStream(fos));
      System.setErr(new PrintStream(ferr))


      2. From the class that launched the process get the
      Process's inputstream (is = p.getInputStream() ) and read
      from it whenever it's available (is.read() ).

      Release Regression From : 1.4
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Review ID: 165805)
      ======================================================================

            mr Mark Reinhold
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: