title: Process.exitValue() and Process.destroy() features
body: <p>I have been experimenting with <code>Process</code> and <code>ProcessBuilder</code> and come with this SSCCE.</p>
  
  <pre><code>        import java.io.IOException;
          public class TestProcess {
              public static void main(String[] args) {
                  Process process = null;
                  ProcessBuilder pb = new ProcessBuilder("notepad.exe");
  
                  try {
                      process = pb.start();
                  } catch (IOException e) {e.printStackTrace();}
  
                  //have some time to close notepad
                  try {
                      Thread.sleep(10*1000);
                  } catch (InterruptedException ignored) {}
  
                  try {
                      System.out.println(process.exitValue());
                   } catch (IllegalThreadStateException e) {
                      System.out.println(e);
                   }
  
                   if (process != null)
                       process.destroy();
  
                   /*try {
                       Thread.sleep(0, 1);
                   } catch (InterruptedException ignored) {}*/
  
                   System.out.println(process.exitValue());
               }
           }
  </code></pre>
  
  <ol>
  <li>If I run this code and close notepad before 10s timeout. <code>destroy()</code> call does not show any problem on attempt to stop already terminated process. <strong>Why?</strong></li>
  <li>If run this code and don't close notepad at all (with commented second sleep) </li>
  </ol>
  
  <p>It seems that destroy is asynchronous call (<strong>just sending a signal?</strong>) which results in exception in second <code>exitValue()</code></p>
  
  <pre><code> java.lang.IllegalThreadStateException: process has not exited
   Exception in thread "main" java.lang.IllegalThreadStateException: process has not exited
          at java.lang.ProcessImpl.exitValue(ProcessImpl.java:246)
          at TestProcess.main(TestProcess.java:30)
  </code></pre>
  
  <ol>
  <li>If I run this code and don't close notepad at all (with uncommented second sleep) then second <code>exitValue</code> never throws Exception, even though sleep value is just 1ms. <strong>Is it because of <code>sleep()</code> overhead itself?</strong>
  Second <code>exitValue</code> would return 1. </li>
  </ol>
  
  <p>PS. I run it from Windows 7 and Eclipse.</p>