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

(process) Process.exitValue() doesn't match subprocess exit value when negative

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0u6
    • core-libs

      OPERATING SYSTEM(S):
      Linux ( and probably all Unix based JDKs )

      FULL JDK VERSION(S):
      java full version "1.5.0_06-b05"

      DESCRIPTION:
      The following testcase illustrates the problem.
      ProcessTest.java
      public class ProcessTest {
          public static void main(String argv[]) {
              try {
                  Process p = Runtime.getRuntime().exec("java Test");
                  p.waitFor();
                  System.out.println("exit = " + p.exitValue());
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      Test.java
      public class Test
      {
        public static void main(String args[])
        {
          System.exit(-10);
        }
      }

      On Windows one gets
      java ProcessTest
      exit = -10

      On Linux one gets
      java ProcessTest
      exit = 246

      This can be a problem on Unix if the WEXITSTATUS macro is not cast to a signed char before assigning to the return value.

            martin Martin Buchholz
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: