Skip to content

Instantly share code, notes, and snippets.

@ajjahn
Created March 3, 2015 00:59
Show Gist options
  • Save ajjahn/de065f4e13435b6610df to your computer and use it in GitHub Desktop.
Save ajjahn/de065f4e13435b6610df to your computer and use it in GitHub Desktop.
#!/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