require 'timeout'
begin
    timeout(5) do
        system("sleep 100")
    end
rescue Timeout::Error
    puts "done"
end

This is turning out to be a very handy library for me. There’s a more extensive example in the wiki:

Ruby FastCGI Timeout