monitoring running processes

I have a script that runs continuously and will deliver a file to multiple servers via scp. On occasions one of the scp's will hang and as a result not complete in sending the remaining files and not loop around again.

If I run the scp commands with a & they'll complete, but I want to make sure the sends have finished before looping again.

My question is how do I monitor the 6 PID's and kill any that have run for more than 2 minutes?

I was going to capture the PID into an array and then use that some how.

Just can't work out the best way.

Any ideas?

They'll be some Christmas cheers for the winner :smiley:

post your code

Not really after Xmas cheers (not in the mood and will never be :D) but here's an idea on how you might monitor and kill any that timed out

#!/bin/sh

TIMER=120
CMD=scp

mysleep()
{
   sleep $1
   CMDPID=`ps -ef |grep $$ |grep $CMD |grep -v grep |awk '{print $2}'`
   for i in $CMDPID
   do
         kill -9 $CMDPID
   done
}

while true
do
        echo Loop ...
        mysleep $TIMER &
        scp ... ... ...
done

Just put 'mysleep 120 &' before scp'ing, proceed with care, not tested :smiley: