Hi, At Wed, 15 Jun 2005 12:40:47 +0900, Ara.T.Howard wrote in [ruby-talk:145444]: > > Let's say I have a ruby script which calls system() to run some > > arbitrary program. Since that program might spiral off into some evil > > infinite-loop, is there some way for me to say "execute this, but for > > no longer than 2 seconds of CPU time"? In the C-world I might use > > something like setrlimit, but I'm not sure how easy that would be to > > do from within a ruby script. Resouce module is in "rough". <http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/rough/ext/resource/> > maybe something like > > harp:~ > cat a.rb > require 'timeout' > def spawn cmd, sec > pid = fork{ system cmd } > begin > Timeout::timeout(sec){ Process::waitpid2(pid).last } > rescue Timeout::Error => e > Process::kill 'TERM', pid rescue nil You should give a chance to terminate gently to the child process, I guess. > Process::kill 'KILL', pid rescue nil -- Nobu Nakada