Put it on a thread, try another thread in x seconds, and then delete the first if it has not already been executed.
process_thread = Thread.new do `sleep 6` # the command you want to run end timeout_thread = Thread.new do sleep 4 # the timeout if process_thread.alive? process_thread.kill $stderr.puts "Timeout" end end process_thread.join timeout_thread.kill
steenslag is nicer though :) This is a low-tech route.
source share