Cygwin: How to stop an application after at most a preset amount of time
Posted on 2005-03-22
I am running a large batch job under Cygwin (Win-XP) which is the same application being executed many times with different input data in a for loop. Occasionally, the application hangs. What I want is to automatically interrupt the app if it does finish in predetermined time. One way to do it is something like this:
my_app ..... &
kill -9 $!
This will launch the app in background, wait for 600 seconds and then kill it if it hasn't finished by itself. The problem is that even if it does finish by itself, this pass of the loop will still complete only after 600 secs. What I want is for it to finish immediately if the application exits normally and only wait for 600 secs if it does not. How can I do it?