Created
December 18, 2012 19:42
-
-
Save thinkerbot/4331233 to your computer and use it in GitHub Desktop.
Switch logging (or whatever) based on a signal in ruby.
This file contains hidden or 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 | |
| # | |
| # 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