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

Runtime exec sometimes returns wrong value from waitFor()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.1
    • 1.0.2, 1.1
    • hotspot
    • None
    • 1.1.1
    • sparc
    • solaris_2.4, solaris_2.5.1
    • Not verified



      Name: mc57594 Date: 02/26/97


      If you have multiple exec()s running, sometimes they return
      each other's status. (This was frequent on 1.01 and 1.02 and
      occasional on 1.1)

      Here are the two shell files you need for the example
      alwaysbad.sh
      #! /bin/sh
      exit 1
      alwaysgood.sh
      #! /bin/sh
      exit 0

      here is the java source that shows the bug
                                                                                      
      public class execbug
      {
          public static void main(String[] args) {
              try {
                  for(int i=0; i < 1000; i++)
                  {
                      Runtime rt = Runtime.getRuntime();
                      String program1 = "alwaysgood.sh";
                      Process p1 = rt.exec(program1);
                      String program2 = "alwaysbad.sh";
                      Process p2 = rt.exec(program2);
                      if(p1.waitFor() != 0) {
                          System.out.println("alwaysgood returned bad on pass "
                              + i);
                      }
                      if(p2.waitFor() != 1) {
                          System.out.println("alwaysbad returned good on pass "
                              + i);
                      }
                  }
              } catch(Exception e) {
                  System.out.println("exception " + e);
              }
          }
      }

      If you run this you should see one or two times that it prints
      out "alwaysbad returned good" and some pass number

      This is causing grief because I am trying to run several streams
      of programs, and I need the exit status be the right one.


      company - Storage Tek , email - ###@###.###
      ======================================================================

            never Tom Rodriguez
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: