Created
March 3, 2015 00:59
-
-
Save ajjahn/de065f4e13435b6610df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts Process.pid | |
SIGNAL_QUEUE = [] | |
reader, writer = IO.pipe | |
[:INT, :QUIT, :KILL, :USR1].each do |signal| | |
Signal.trap(signal) do | |
writer.write_nonblock('.') | |
SIGNAL_QUEUE << signal | |
end | |
end | |
loop do | |
case SIGNAL_QUEUE.pop | |
when :INT | |
puts "received INT" | |
exit | |
when :QUIT | |
puts "received QUIT" | |
exit | |
when :KILL | |
puts "received KILL, but won't quit" | |
when :USR1 | |
puts "received USR1" | |
else | |
ready = IO.select([reader]) | |
if ready[0].include?(reader) | |
reader.read_nonblock(1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment