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

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

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.4.1
    • Fix Version/s: 5.0
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Build:
      1.4.1
    • Introduced In Version:
    • Resolved In Build:
      tiger
    • CPU:
      x86
    • OS:
      linux

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: