I have several simulations to do, each is invoked with python simulate.py <parameter list>. The problem with these simulations is that some of them hang without quiting, which prevents me from running them in batch with a simple script.
What I'd need, is some form of "run-time-constraint" command, that would automatically kill the process (preferably by virtually pressing Ctrl+C, but I think simple kill will do as well) after a specified time, if the process didn't end gracefully by itself.
Of course I can write such script myself, but I suspect that someone have done it already before me, so I don't have to reinvent the wheel spending hours with ps, time and bash manuals.
myProgramfinishes in less time thansleep(not an unreasonable assumption since the goal is to set a maximum allowed runtime). You then send a signal either to a non-existent PID (no real harm done) or to any random process on the system (potentially fatal). – user May 06 '13 at 11:36timeoutcommand does exactly what he's looking for, waiting for the OP to respond to my comments. – slm May 06 '13 at 11:38timeoutshould be the solution I need. I'm testing it at the moment – Adam Ryczkowski May 06 '13 at 11:38timeoutapproach is better, but on one's own system the sleep approach is effectively safe. – mattdm May 06 '13 at 15:37timeoutoption first to cut down on anyone finding the less optimal method down the road, and running with it 8-). – slm May 06 '13 at 17:32timelimitinstead oftimeout. – Adam Ryczkowski May 06 '13 at 18:52