Hi!
I'm using a script to start a process that might run forever if some parameters are given wrong (it's part of an optimization). I would now like to have the process killed after a certain walltime in that case. So far I get it done with the following lines
./My_process.e &
pid=`ps -ef | grep $$ | grep My_programme.e | grep -v grep | awk '{print $2}'`
sleep $Walltime
if kill -0 $pid 2>/dev/null;then
kill -TERM $pid
fi
This works but is not very convenient as the shell always is in sleep mode for $Walltime seconds, even if "My_process" runs properly and finishes after say 15 seconds. As I am calling this programme several hundred times and the walltime currently is 25 seconds it takes very long. It would be nice if the script would continue when the process is running properly and finishes by itself. I thought of something like "while sleep..." but can't figure it out....is there any way to do it like that or are there other nice ways?
Thankful for any hint,
ciwstevie