0

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
4

1 回答 1

0

由于将评论标记为答案的功能请求仍然被拒绝,因此我在此处复制上述解决方案。

如果您只对每 3 秒检查一次感兴趣,为什么不在循环中 sleep 3 呢?——格里沙·莱维特

于 2013-09-09T07:46:37.937 回答