I\'m trying to fork a sub-process, wait for it to finish, if it doesn\'t finish within a certain amount of time, kill it.
This is what I have so far:
ser
Use the Timeout module: (code from http://www.whatastruggle.com/timeout-a-subprocess-in-ruby)
require 'timeout'
servers.each do |server|
pid = fork do
puts "Forking #{server}."
output = "doing stuff here"
puts output
end
begin
Timeout.timeout(20) do
Process.wait
end
rescue Timeout::Error
Process.kill 9, pid
# collect status so it doesn't stick around as zombie process
Process.wait pid
end
puts "#{server} child exited, pid = #{pid}"
end