title: How to trap signal in Ruby process
body: <p>I want to trap a signal sent to a Ruby process.</p>
  
  <p>The process is the following file, called wait.rb:</p>
  
  <pre><code>sleep 60
  
  Signal.trap(15) {
    puts "caught signal 15!"
  }
  </code></pre>
  
  <p>I run wait.rb, and in another bash shell find the PID of wait.rb and execute:</p>
  
  <pre><code>kill -15 pid
  </code></pre>
  
  <p>I expected that "caught signal 15!" would be printed in the first shell where I executed wait.rb, but it is not. Instead, I get this output:</p>
  
  <pre><code>Terminated: 15
  </code></pre>
  
  <p>Why is the <code>puts</code> statement in the <code>Signal.trap</code> block not executed?</p>