4

I have written a shell script to initiate three background process in the same time. In shell script I am trying to wait for all children to finish their job and then the parent job to terminate. But, with some reason I see the the sleeping processes never awakes.

echo "Starting $1 instances" >> $logfile
for i in `seq 1 $1`
do
        /usr/bin/php index.php name&
done

echo "Waiting for all $l instances to complete \n" >> $logfile
wait
echo "All $instances scripts completed"  >>  $logfile

1 Answers1

7

If you are using bash, you should use the wait command, rather than an elaborate polling loop. I don't know about other shells (sh, zsh, and so on), but I assume most/all of them also have wait, or an equivalent to it.

Steven Monday
  • 14,179