Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Allow the application to trap POSIX signals. Take a look at the <a href="http://www.ruby-doc.org/core-1.9.3/Signal.html" rel="nofollow">Signal class</a>.</p> <p>If you send a <code>kill &lt;signal type&gt;</code> to the process, any signal handlers will be invoked, regardless of what the process is currently doing. You can, for example, set some sort of flag that is checked at a sensible point in your logic (at the end of a run loop, for example), terminating the process if that flag is set. There are <a href="http://en.wikipedia.org/wiki/Signal_%28computing%29" rel="nofollow">many signals</a> you can respond to, but <code>SIGHUP</code> or one of the <code>SIGUSR</code> signals probably make sense for what you're doing... you can respond to whatever signal you like in whatever way you like, but it makes sense to allow the default behaviour for most of the typically handled ones (like <code>SIGTERM</code> and <code>SIGKILL</code>). For really complex stuff, you can actually accept a coded series of signals to trigger particular events too.</p> <pre><code>Signal.trap("HUP") do puts "Huh?" end loop do puts "Looping..." sleep 2 end </code></pre> <p>Output</p> <pre><code>[chris@chipbook:~%] ruby sig_demo.rb Looping... Looping... Looping... Looping... Looping... Huh? Looping... Looping... Looping... Huh? Looping... Looping... Looping... </code></pre> <p>Because in another terminal window I'd done:</p> <pre><code>[chris@chipbook:/usr/local%] ps aux | grep ruby chris 69487 0.0 0.0 2425480 188 s005 R+ 11:26pm 0:00.00 grep ruby chris 69462 0.0 0.1 2440224 4060 s004 S+ 11:26pm 0:00.03 ruby sig_demo.rb [chris@chipbook:/usr/local%] kill -HUP 69462 [chris@chipbook:/usr/local%] kill -HUP 69462 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload