title: How to use signal blocking in Ruby
body: <p>How does one block certain signals in Ruby? (I.e. sigprocmask, as described here: <a href="http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html#SEC371" rel="noreferrer">http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_21.html#SEC371</a>)</p>
  
  <p>Here is my example code</p>
  
  <pre><code>pid = fork do
    trap('INT') do
      puts "Graceful shutdown..."
      puts "goodbye"
      exit 0
    end
  
    loop do
      this_could_be_interrupted
      something_that_must_not_be_interrupted
      this_could_be_interrupted_too
    end
  end
  
  sleep 5
  Process.kill('INT', pid)
  </code></pre>
  
  <p>Can I wrap <code>something_that_must_not_be_interrupted</code> in a ruby block or something to ensure that SIGINT won't be process while that method is running?</p>
  
  <p>I guess the ideal would be if I could do something like this:</p>
  
  <pre><code>Process.block_signal('INT') do
    something_that_must_not_be_interrupted
  end
  </code></pre>
  
  <p><strong>UPDATE</strong>: I'm currently doing something like this:</p>
  
  <pre><code>trap('INT') do
    @interrupted = true
  end
  
  loop do
    exit 0 if @interrupted
    something_that_must_not_be_interrupted
  end
  </code></pre>