Skip to content

Instantly share code, notes, and snippets.

@roidrage
Created January 23, 2014 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roidrage/8585266 to your computer and use it in GitHub Desktop.
Save roidrage/8585266 to your computer and use it in GitHub Desktop.
A little script to run a command wrapped in a timeout. The command will be terminated after the timeout expired
max_runtime = ARGV.shift.to_i
pid = Kernel.fork do
`#{ARGV.join(" ")}`
end
trap :CHLD do
puts 'Child exited'
exit
end
sleep max_runtime
puts 'Timeout expired, killing process'
Process.kill(:TERM, pid)
ruby forkify.rb 600 bundle exec rake test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment