From: Glen Holcomb Date: 2008-12-05T23:08:33+09:00 Subject: Re: Force a program to stop if runtime exceeds given duration ------=_Part_28135_21085778.1228486474909 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, Dec 5, 2008 at 6:59 AM, Aldric Giacomoni <"aldric[remove]"@ trevoke.net> wrote: > Everybody automatically assumes that rubyists are using Linux - sadly, in > the medical field Linux is not an option unless you're working with the > modality itself. Medical software is almost all Windows-based.. So, Windows > is where I am for this issue and Windows is where I remain :( > If it were for an outside-Ruby solution, I can think of tons of options. I > just want a program which works and does everything all by itself.. Because > if I have to deploy this to 400 machines, I don't wanna have to do any more > setup work than absolutely required. > > > Ron Fox wrote: > >> See http://www.ruby-doc.org/core-1.9/classes/Process.html#M003012 >> >> It and sleep have all the tools you need to do this. The idea is that you >> have a master process that forks the child process which runs the script you >> want to time. The master process then loops. The loop >> sleeps a bit then calls waitpid with the WNOHANG flag to see if the child >> has exited. Count the sleep time, or use Time to figure out how long you've >> been waiting.. Once you've waited long enough, use kill >> to kill the child process. If the child has exited.. the master process >> exits. >> >> The length of your sleep in the loop of the master process determines >> - The precision with which you measure the timeout. >> - The latency with which the master process responds to normal child exit. >> >> Ron. >> >> Aldric Giacomoni wrote: >> >>> Any idea how to do that? >>> Say, I don't want a program to run longer than 5 hours.. How would that >>> be implemented? >>> >>> --Aldric >>> >> >> >> > I'm in the same boat here at work. Fork won't work in Windows so that option is out. However if the thread or timeout suggestions don't work for you it might be possible to adjust Robert's suggestion to run as a Windows Task. I don't know if you can put a time limit on a task though (don't use them very often). -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_28135_21085778.1228486474909--