title: How to detect pending system shutdown on Linux?
body: <p>I am working on an application where I need to detect a system shutdown. 
  However, I have not found any reliable way get a notification on this event. </p>
  
  <p>I know that on shutdown, my app will receive a <code>SIGTERM</code> signal followed by a <code>SIGKILL</code>. I want to know if there is any way to query if a <code>SIGTERM</code> is <em>part of a shutdown sequence</em>? </p>
  
  <p>Does any one know if there is a way to query that programmatically (C API)?</p>
  
  <p>As far as I know, the system does not provide any other method to query for an impending shutdown. If it does, that would solve my problem as well. I have been trying out <code>runlevels</code> as well, but change in <code>runlevels</code> seem to be instantaneous and without any prior warnings.</p>