finding Background Process Id

Hi Gurus,
How can i find background process is completed or not. I have mentioned my scenario below.

Actually Pr1 Process is running in back ground, i just want to know whether this process completed or not. I can come to know the process id by typing pid=$! but i want to trigger that pr1 process in back ground and then after 10 min i want to trigger Pr2 Process. Actually Pr1 Process will take around 2 Hr time. i don't want to wait till 2Hrs, by writing wait $pid where $pid=$!.

script:
*****

x=`1 2 3 4 5`
for y in $x
do
if [ $a -eq 0 ]
then
./$Home/script_1.sh &
pid_1=$!
wait $pid_1
elif [ $b -eq 0 ]
then
./$Home/script_2.sh &
pid_2=$!
wait $pid_2
fi
sleep 15
done

here n this case for every 15 sec i want to run the scripts which has completed its process. in this case first it will run script_1.sh then it will wait for the process to complete then it triggers the script_2.sh but i don' t want to wait till script_1.sh completes. For every 15sec i want too run which ever is free i.e if for after 45 sec script_1.sh is completed its processing the it shuld run.

Please help me on the same.

What you could do is have a temporary file which is created when you start to run a script, then you delete when the script finishes.

You then have a single loop with a sleep which looks at what temporary files exist and then decides what should be started.

Hi,
can u send any sample code.

something like...,

#!/bin/sh

rm dead.tmp

run_one()
{
    touch one.tmp
    ./one.sh
    rm one.tmp
    echo $$ >>dead.tmp
}

run_two()
{
    touch two.tmp
    ./two.sh
    rm two.tmp
    echo $$ >>dead.tmp
}

....

while true
{
       sleep 15

       if test -f dead.tmp
       then
          mv dead.tmp reap.tmp
          for d in `cat reap.tmp`
          do
             wait $d
          done
          rm reap.tmp
       fi

       for d in one two ....
       do
               if test ! -f $d.tmp
               then
                      run_$d &
                      break
               fi
       done
}

Hi,
Thanks for responding...

Actually my requirement is as follows.

i had 5 Processes for every 30 min i want to run.for every 30 min i need to check which process is free.then i will kick off that process.

this scenario will work for the previous code.