title: Signals received by bash when terminal is closed
body: <p>Use trap to capture signals like this:</p>
  
  <pre><code>i=-1;while((++i&lt;33));
  do
      trap "echo $i &gt;&gt; log.txt" $i;
  done
  </code></pre>
  
  <p>And close the terminal by force.</p>
  
  <p>The content in log.txt is then (under redhat linux):</p>
  
  <blockquote>
    <p>1</p>
    
    <p>18</p>
    
    <p>1</p>
    
    <p>17</p>
    
    <p>0</p>
  </blockquote>
  
  <p>Where these signals from?</p>