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

(process) Process.exitValue() returns random value if child killed (lnx)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.1
    • core-libs
    • None
    • 1.4.1
    • tiger
    • x86
    • linux

      If you use Runtime.exec() on Linux to create a process which is subsequently
      killed by a signal, the exit value returned by
      Process.waitFor() and
      Process.exitValue() is unexpected.

      Consider this code:

      ------------------------------------------------------------------------
      public class KilledExitValue {

          public static void main (String[] args) throws Exception {
      Process proc = Runtime.getRuntime().exec
      (new String[] { "sh", "-c", "kill -9 $$" });
      System.out.println(proc.waitFor());
      System.out.println(proc.exitValue());
          }
      }
      ----------------------------------------------------------------------
      On Solaris, this prints:
      9
      9

      On Linux, it prints a random value greater than 128.
      Java 1.5 prints
      248
      248

      while 1.4.2 prints
      129
      129

      The Solaris behavior does not allow one to distinguish between a process
      that did "exit (9)" and one that was killed by signal 9.

      The intent on Linux is that in case of a signal, the exit value is
      128 + signo, but the implementation is buggy.

      The correct and expected behavior is to always return 128+signo,
      which allows one to distinguish between normal and abnormal termination,
      and is exactly the behavior of Unix shells:

      $ sh -c 'kill -9 $$'; echo $?
      Killed
      137
      ###@###.### 2003-06-03

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: