Skip to content

Instantly share code, notes, and snippets.

@jschairb
Last active December 16, 2015 12:19
Show Gist options
  • Save jschairb/5434124 to your computer and use it in GitHub Desktop.
Save jschairb/5434124 to your computer and use it in GitHub Desktop.
require 'open3'
require 'timeout'
def subprocess_sleep(seconds)
Open3.popen3("sleep #{seconds}")
end
begin
Timeout.timeout(2) do
stdin, stdout, stderr, wait_thr = subprocess_sleep(3)
@pid = wait_thr.pid
Process.wait(@pid)
end
rescue Timeout::Error
puts "Sleep PID: #{@pid}"
Process.kill 9, @pid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment