Skip to content

Instantly share code, notes, and snippets.

@zmalltalker
Last active June 17, 2016 11:49
Show Gist options
  • Save zmalltalker/d408d79d801a7f364b7ddfa03b3a9478 to your computer and use it in GitHub Desktop.
Save zmalltalker/d408d79d801a7f364b7ddfa03b3a9478 to your computer and use it in GitHub Desktop.
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