title: How does trap / kill work in bash on Linux?
body: <p>My sample file</p>
  
  <p>traptest.sh:</p>
  
  <pre><code>#!/bin/bash
  trap 'echo trapped' TERM
  while :
  do
    sleep 1000
  done
  </code></pre>
  
  <p>$ traptest.sh &amp; </p>
  
  <blockquote>
    <blockquote>
      <p>[1] 4280</p>
    </blockquote>
  </blockquote>
  
  <p>$ kill %1      &lt;-- kill by job number works</p>
  
  <blockquote>
    <blockquote>
      <p>Terminated</p>
      
      <p>trapped</p>
    </blockquote>
  </blockquote>
  
  <p>$ traptest.sh &amp; </p>
  
  <blockquote>
    <blockquote>
      <p>[1] 4280</p>
    </blockquote>
  </blockquote>
  
  <p>$ kill 4280     &lt;-- kill by process id doesn't work?</p>
  
  <blockquote>
    <blockquote>
      <p>(sound of crickets, process isn't killed)</p>
    </blockquote>
  </blockquote>
  
  <p>If I remove the trap statement completely, kill process-id works again?</p>
  
  <p>Running some RHEL 2.6.18-194.11.4.el5 at work.  I am really confused by this behaviour, is it right?</p>