From: ptkwt@...2.teleport.com (Phil Tomson) Date: 2000-12-19T05:10:02+09:00 Subject: [ruby-talk:7597] timeout question I need to be able to timeout of an operation that has hung (typically, it's some command sent to the system [ie. system("someprog")] that I need to timeout of after a few minutes). I found the timeout command in the book (pg 464) and tried it with a toy program: require "timeout" returnval = timeout(1.5) do sleep(30) end print "I'm awake!\n" print "return value is: #{returnval}\n" It times out fine, but the problem is that the print commands never get executed either - the timeout seems to kill not only the operation that was being timed, but the whole script. What I need is something that sets a timer and waits for it to complete - if the timed operation has become 'stuck' I need to kill it when the timer times out and then continue on with the rest of the program. Another related question: In the case of a system call that is being timed, does the process that was spawned on the system actually get killed? For example if I have: retval = timeout(100) do system("my_prog -args") end If the timer gets to 100 seconds will the program my_prog be sent some kind of TERM signal? (probably not, but I can only hope - that's what I would like it to do :) OK, more realistically, How can I figure out the pid of the spawned my_prog so I can send a TERM to it when the timer times out? Phil