I was using bash to run different java programs.
For some programs, there are bugs that will run into infinity loops, so I want to set up time limit like 5 seconds. If the program cannot finish within 5 seconds, the bash script should continue running other programs instead of waiting the current program ends.
I have tried
timeout 5 java <my program>
But still my script won't proceed when it encounters the problematic program.
I have also tried the script providing here: http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3 with no luck that my script still won't proceed.
Another command I have tried was
( /path/to/slow command with options ) & sleep 5 ; kill $!
When I ran my script using above command, it said process id not found when in reality it's still running the problematic program.
I wonder if anyone has tried to timeout a running java program that runs into infinity loops. If so, Please shed some light!
Btw, using ctr+c at the time the program enters infinity loops can make the program stop and the script will proceed to next one.