Last active
June 17, 2016 11:49
-
-
Save zmalltalker/d408d79d801a7f364b7ddfa03b3a9478 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
module TimeoutFork | |
def self.run(command, timeout=2) | |
if child_pid = fork | |
sleep timeout | |
Process.kill("KILL", child_pid) | |
yield | |
else | |
exec command | |
end | |
end | |
end | |
TimeoutFork.run("ruby child.rb", 1) do | |
puts "We got a bad one" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment