Last active
December 14, 2017 04:42
-
-
Save ccutrer/d3b8ee33e73a51c48894c5dfd26dc67e 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 | |
require 'timeout' | |
trap(:CHLD) { } | |
x = 0 | |
while true | |
puts "loop #{x += 1}" | |
pid = Process.spawn('sleep 1') | |
Timeout.timeout(30) do | |
Process.waitpid(pid) | |
end | |
end |
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 | |
require 'timeout' | |
self_pipe = IO.pipe | |
signal_queue = [] | |
def wake_up(self_pipe) | |
self_pipe[1].write_nonblock('.', exception: false) | |
end | |
trap(:CHLD) { signal_queue << :CHLD; wake_up(self_pipe) } | |
signal_processor = Thread.new do | |
loop do | |
self_pipe[0].read(1) | |
signal_queue.pop | |
end | |
end | |
x = 0 | |
while true | |
puts "loop #{x += 1}" | |
pid = Process.spawn('sleep 1') | |
Timeout.timeout(30) do | |
Process.waitpid(pid) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment