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

exec() only works correctly the first time called

    XMLWordPrintable

Details

    • 1.0.2
    • sparc
    • solaris_2.4
    • Not verified

    Description

      I'm having problems execing programs more than once.

      The SIGCHLD handler only gets called with the first exec. Subsequent exec calls seem
      to be handled differently. I can verify this because only the first exec prints the messages
      pid 14494 status 0
      Received sigchild for 14494 exit=0

      I'll enclose a sample program and it's output.

      ls.java:
      public class ls {
          public ls(String file) {
              String args[] = new String[2];
              Process p;
              String buf;
              InputStream s;
              int length;

              args[0] = "/bin/ls";
              args[1] = file;
              try {
                  p = Runtime.getRuntime().exec(args);
                  s = p.getInputStream();
                  DataInputStream din = new DataInputStream(s);

                  while ((buf = din.readLine()) != null) {
                      System.out.println(buf);
                  }
              } catch (IOException e) {
                  System.out.println("command failed.");
              }
              System.out.println("got to here");
          }

          public static void main(String args[]) {
              if (args.length == 0) {
                  System.out.println("enter file");
              } else {
                  System.out.println("first ls for " + args[0]);
                  new ls(args[0]);
                  System.out.println("second ls for " + args[0]);
                  new ls(args[0]);
              }
          }
      }

      holiday% javac ls.java
      holiday% java ls /tmp/foo
      first ls for /tmp/foo
      pid 14625 status 0
      Received sigchild for 14625 exit=0
      file1
      file2
      file3
      got to here
      second ls for /tmp/foo
      file1
      file2
      file3

      The program never exits, and as you see, the sigchild message only got printed on
      the first exec

      Attachments

        Issue Links

          Activity

            People

              tlindholsunw Timothy Lindholm (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: