Run script in parallel in while loop

Hi
I am running a loop which actually runs same script for different argument value passed to it.

while read repID
do
echo "Starting for $repID";
date;
perl process_report.pl $repID 
done<${FILE_TO_READ}

However this runs in sequence.
I want the loop to not to wait for perl to complete before moving to next record.
So basically , it should call the perl script and move to next line of while loop. I want to run multiple instances of perl via while loop.
Is adding "&" will work fine ?

Thanks in advance
--Raj

Hi dashing201

Yes this (&) should work.
Also, you could embrace it in brackets (perl process_report.pl $repID) .

This behaves the same (in this situation, there's a diffrence between the two i cannot explain), as long you dont want to fetch variables, but from the read, i'd guess you're writing the reports of that specific id...

Hope this helps

Hello,

You can run the scripts in background, like following is an example for sleep process run in background.

Lets say a file in which number of mins/seconds have been given.(Input file).

cat file23
60
50
80
20
10
100

Now lets say we have a shell script same like your perl script. which needs to be executed in while loop.

cat test2.ksh
Q=$1
echo "starting sleep for" $Q "mins."
sleep $Q

Here is the example of While loop for same.

while read line
do
echo "Executing for" $line
./test2.ksh $line &
done < "file23"
Executing for 60
[1] 20921
Executing for 50
[2] 20922
Executing for 80
[3] 20923
Executing for 20
starting sleep for 60 mins.
[4] 20924
Executing for 10
starting sleep for 50 mins.
[5] 20931
starting sleep for 80 mins.
Executing for 100
[6] 20934

Hope following example may help you, similarly you can too put all proccesses in background while calling your perl script use at last
perl process_report.pl $repID & .

Thanks,
R. Singh

Hi Ravinder/Sea

Thanks for the quick reply.
However if I have to implement a check to confirm if all the process have been completed then how can I do it ?
It is required to make sure that all parallel instances are completed before I change status to complete.

Thanks
Raj