On Dec 4, 2008, at 1:54 PM, Avdi Grimm wrote:
> require 'timeout'
>
> HOURS = 60 * 60                 # seconds, minutes
> time_limit = 5 * HOURS
>
> begin
>  Timeout.timeout(time_limit) do
>    # your program goes here
>  end
> rescue Timeout::Error
>    puts "Program has exceeded allotted time, exiting."
> end
>
> --  
> Avdi
>
> Home: http://avdi.org
> Developer Blog: http://avdi.org/devblog/
> Twitter: http://twitter.com/avdi
> Journal: http://avdi.livejournal.com


In particular, this can't interrupt system calls and can even be  
foiled by something as "simple" as a nasty, poorly-written,  
backtracking regexp that will eventually complete, but might consume  
resources for several more hours.  (This one bit me once, can you  
tell? ;-)

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com