This code is untested, the aim is to check the size of the output file every 3 secs and kill myprogram if it stops increasing. It should also be killed after 60 secs regardless.
This script will be run multiple times triggered by the events of an overall script.
My question is, id there a more efficient way to achieve the monitoring of the file sizes with out running dozens of 1 sec timers.
Perhaps a script running a master 1 sec timer who's output is piped into all of the file size monitoring scripts as and when they're run?
myprogram >> ~/log/$$.txt
pid=!$
filesize='1'
counter='0'
counter2='0'
while ((counter<61))
do
((counter++))
((counter2++))
if (( $counter2 == "3" )) ;
then
counter2='0'
lastfilesize=$filesize
filesize=$(stat -c%s "~/log/$$.txt")
if (( $filesize == $lastfilesize )) ;
then
kill $pid
fi
fi
sleep 1
done
if (( $counter == 61 )) ;
then
kill $pid
fi
exit