Reputation: 188
I am using below logic to execute an SQL in parallel
PID_LIST="start"
while [ "$PID_LIST" ]
do
$count =0
if [ "z$PID_LIST" = "zstart" ]
then
PID_LIST=""
fi
for PID in $PID_LIST
do
# echo "Checkpid $PID"
if kill -0 $PID >/dev/null 2>&1
then
PID_LIST_TMP="$PID_LIST_TMP $PID"
$count =`expr $count + 1`
fi
done
PID_LIST=$PID_LIST_TMP
if [ $more_re_to_process -eq "Y" ]
then
while [ $count -le $MAX_INSTANCE ]
do
#prepare input for sql
invoke SQL script sql1 with prepared one >LOG_$count
PID_LIST = PID_LIST="$PID_LIST $!"
done
fi; done
In this example whenever any sql process finishes I am creating a new one. But the problem is that I end up creating a new log. I want that whenever I create a new SQL session it uses the the LOG file of process which is finished (if any).
Could someone tell How Can I do this?
Upvotes: 1
Views: 39
Reputation: 19395
Provided that the shell handles arrays, you could store the PIDs as elements in an array and clear only the element if a process finishes, so that the indexes of the other processes remain the same; then in a loop for invoking new processes scan for cleared elements; with the array index $count
, >LOG_$count
uses the the LOG file of process which is finished.
Upvotes: 1