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

(process) Cannot spawn(fork) off a new process

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_7

      Description



      Name: yyT116575 Date: 03/09/2001


      Solaris VM (build Solaris_JDK_1.2.1_04, native threads, sunwjit)
      to
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      /*
       * @(#)BugTest.java 03/09/2001
       *
       */

      /**
       * @author Neal Ho ###@###.###
       * @version 1.0, 03/09/2001
       * @since
       */

      import java.io.*;
      import java.math.*;
      import java.sql.*;
      import java.sql.Timestamp;
      import java.text.*;
      import java.util.*;
      import java.util.Date;


      public class BugTest
      {
        /**
         * main
         */
        public static void main(String args[]) throws Exception
        {

          int aCount = 0;
          String aCommand[] = null;
          int aWaitFor = 0;
          Process aProcess = null;
          while (true)
          {
            aCommand = new String[3];
            aCommand[0] = "/usr/bin/ksh";
            aCommand[1] = "-c"; // tell sh to use the next string as a shell command
            aCommand[2] = " ls " ;
            //Thread.currentThread().sleep(1000);
            try
            {
              System.err.println("Test Bug");
              aProcess = Runtime.getRuntime().exec(aCommand);
              aWaitFor=aProcess.waitFor();
            }
            catch (IOException e)
            {
              e.printStackTrace();
            }
            System.out.println("The number of calls (" + ++aCount + ")");
          }

        }
      }
      (Review ID: 118517)
      ======================================================================

        Activity

        Hide
        iris Iris Clark added a comment -
        BT2:EVALUATION

        What makes you believe that the process isn't being forked? My guess is that
        you draw this conclusion because you're not seeing the output of the "ls". To
        see the output stream from the spawned process, you'll need to modify your
        code as follows:

        import java.io.*;

        public class BugTest {
            public static void main(String args[]) throws Exception {
                int aCount = 0;
                String aCommand[] = null;
                int aWaitFor = 0;
                Process aProcess = null;
                while (true) {
                    aCommand = new String[3];
                    aCommand[0] = "/usr/bin/ksh";
                    aCommand[1] = "-c"; // tell sh to use the next string as a shel
        l command
                    aCommand[2] = " ls " ;
                    //Thread.currentThread().sleep(1000);
                    try {
                        System.err.println("Test Bug");
                        aProcess = Runtime.getRuntime().exec(aCommand);

                        // read the output stream for the spawned process
                        Reader in = new InputStreamReader(aProcess.getInputStream());
                        int c;
                        while ((c = in.read()) != -1)
                            System.out.print((char) c);
                        in.close();
                            
                        aWaitFor=aProcess.waitFor();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    System.out.println("The number of calls (" + ++aCount + ")");
                }
            }
        }

        The expected output was observed in jdk1.3 and jdk1.4-beta3-b83. This is
        a user error.

        -- iag@sfbay 2001-10-17
        Show
        iris Iris Clark added a comment - BT2:EVALUATION What makes you believe that the process isn't being forked? My guess is that you draw this conclusion because you're not seeing the output of the "ls". To see the output stream from the spawned process, you'll need to modify your code as follows: import java.io.*; public class BugTest {     public static void main(String args[]) throws Exception {         int aCount = 0;         String aCommand[] = null;         int aWaitFor = 0;         Process aProcess = null;         while (true) {             aCommand = new String[3];             aCommand[0] = "/usr/bin/ksh";             aCommand[1] = "-c"; // tell sh to use the next string as a shel l command             aCommand[2] = " ls " ;             //Thread.currentThread().sleep(1000);             try {                 System.err.println("Test Bug");                 aProcess = Runtime.getRuntime().exec(aCommand);                 // read the output stream for the spawned process                 Reader in = new InputStreamReader(aProcess.getInputStream());                 int c;                 while ((c = in.read()) != -1)                     System.out.print((char) c);                 in.close();                                      aWaitFor=aProcess.waitFor();             } catch (IOException e) {                 e.printStackTrace();             }             System.out.println("The number of calls (" + ++aCount + ")");         }     } } The expected output was observed in jdk1.3 and jdk1.4-beta3-b83. This is a user error. -- iag@sfbay 2001-10-17

          People

          • Assignee:
            iris Iris Clark
            Reporter:
            yyoungsunw Yung-ching Young (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Imported:
              Indexed: