Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created December 18, 2012 19:42
Show Gist options
  • Save thinkerbot/4331233 to your computer and use it in GitHub Desktop.
Save thinkerbot/4331233 to your computer and use it in GitHub Desktop.
Switch logging (or whatever) based on a signal in ruby.
#!/usr/bin/env ruby
#
# terminal1> ruby logswitch.rb
# terminal2> kill -s USR1 $(cat pid_file)
#
File.open("pid_file", "w") do |io|
io.puts Process.pid
end
char = "."
Signal.trap("USR1") do
char = (char == "." ? "!" : ".")
end
while true
$stdout.printf char
$stdout.flush
sleep 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment