Problem with storage of PID's to variables

I have the following problem to be solved:
I read a .csv file (tempfile), fetch the values into variables F1 to F5.
Variables F1, F2, F3 are parameters used for running a program (blablaprogram).
Variable F4 I want to use to store the PID-value in and variable F5 is used for storing the return value of the wait-process.
I want to distinquish the several parallel processes and monitor if they are finished. Problem is that I cannot store the PID into variables and read the content of the variable. At the line : echo "\n\t`date`:\t$F4 ........ , $F4 contains the variablename that has been read from the flatfile i.o. the PID.
Has anyone a suggestion?

The code (KSH) is shown underneath:

IFS=","
while read F1 F2 F3 F4 F5
do
blablaprogram $F1 $F2 > $LOGDIR/bes006_$F3.log 2>&1 &
set $F4=$!
echo "\n\t`date`:\t$F4 is Process ID for job waiting on $F1$F2"
wait $F4 # Wait until background process $F4 completes ...
set $F5=$?
echo "\n\tPID $F4: blabla Return Value for $F1$F2 concatination is: $F5"
case $F5 in
0) echo "\n\tConcatination on $F1$F2 COMPLETED Successfully"
;;
1) echo "\n\t!!! WARNING: Likely DATA ERROR ... !!!"
;;
2) echo "\n\t!!! FATAL ERROR ... !!!"
ERRORS=10; exit $ERRORS
;;
esac
echo "\n\t*********************************************************************"
done < $TEMPFILE
IFS=" "

A process can only wait for its children. You can't wait for some random pid. You can loop until the process is no longer running. But then you will not be able to get the exit code. Maybe the process in question could be run by a wrapper which waits for it, obtains the exit code, and write it to a file or something.

Thanks for quick feedback!
For the time being I've decided to process the jobs sequentially i.o. parallel. By creating an array I can store the PID's to this array and use it for the waiting step.

That's right.
But what, from my point of view, is a little bit confusing is the "set $F4=$!". I mean, why "set $F4"? I would use simply "F4=$!"...
Continuing with what Perderabo said, perhaps this could help you :slight_smile:

#!/bin/bash

for i in 1 2 3 4 5 6 7 8 9; do
   (
   sleep 10 &
   wait $!
   echo "sleep $i output was: $?"
   ) &
done

Tested in bash.

Regards.