From: Xeno Campanoli Date: 2009-03-25T05:23:43+09:00 Subject: Re: Looking for a method to kill all children for my Timeout::Error contingency Jos Backus wrote: > On Wed, Mar 25, 2009 at 04:57:03AM +0900, Xeno Campanoli wrote: >> Do I really need to collect all the pids from fork to kill them in that case, or >> is there a method I'm not finding in pickaxe that just does it??? > > Here's a trick I use, maybe it is useful. Note that even if push-to-slaves > creates children, those too will be killed because they reside in the same > process group. The problem with that is I have many processes, so I would be doing this with arrays and loops, which suddenly becomes problematic. If I could just call something that automatically kills the entire tree of children on down that would be much nicer...?? > > require 'timeout' > signal = '-TERM' > timeout = 30 > > pid = Process.fork do > Process.setsid > exec %{push-to-slaves -v} > end > begin > Timeout::timeout(timeout) { Process.waitpid(pid) } > rescue Timeout::Error => exc > puts "#{exc.message}, killing pid #{pid}" > Process.kill(signal, pid) > res = Process.waitpid(pid) > puts "pid #{pid.inspect} != res #{res.inspect}" if res != pid > end > -- "Facts do not cease to exist because they are ignored" - Aldous Huxley "...Or I might add, because they are denied" - Dr. Albert A. Bartlett http://www.eskimo.com/~xeno