title: How can my process detect if the computer is shutting down?
body: <p>I'm running some applications on EC2 spot instances. Such instances can be killed by Amazon with no notice.</p>
  
  <p>In the shutdown process, processes are killed in some order.  We have monitoring/recovery programs that should behave differently based on whether the server is shutting down or the process just crashed. (specifically we don't want to do anything if the server is actually shutting down)</p>
  
  <p>How can I detect in the recovery process (if it is still alive) that processes were killed because of a shutdown?</p>
  
  <p>(More system details: I'm running unknown/untrusted/etc code in a sandbox that doesn't modify external state. Generally if sandboxed code crashes, it is fault of author of the untrusted code and we will not rerun it.  But if the sandboxed code is terminated due to the VM shuting down or failing, we need to rerun it on another instance.  The problem I'm having right now is that the user's code is terminated first so the monitoring program incorrectly believes the crash is user error.)</p>