title: Java - programmatically set exit code from SIGTERM
body: <p>Situation:  I have a keep-alive shell script that restarts an application whenever it shuts down.  However I do not want it to do this if the application was closed via a <code>SIGTERM</code> or <code>SIGINT</code> (<code>kill</code>, <code>Ctrl+C</code>, etc.) i.e. a shutdown hook.  However I have no way of setting the exit code, hence communicating to the keep-alive script, when exiting from a shutdown hook as calling <code>exit</code> is illegal.</p>
  
  <p>From Javadocs for <code>exit</code>:</p>
  
  <blockquote>
    <p>If this method is invoked after the virtual machine has begun its shutdown sequence then if shutdown hooks are being run this method will block indefinitely. If shutdown hooks have already been run and on-exit finalization has been enabled then this method halts the virtual machine with the given status code if the status is nonzero; otherwise, it blocks indefinitely.</p>
  </blockquote>
  
  <p>Is this possible?</p>