Hi,
I need to write a Shell Script wherein i will connect to a DB2 Database and run multiple DB procedures. I know how to do in a way where procedures will be called one after the other, like when first procedure finishes, second will be executed.
But what i want is to run them at the same time like we execute background processes. Is there a way to achieve this.
After started bg process, save child process process id (variable !).
db2 "Call PROC1" &
pid1=$!
db2 "Call PROC2" &
pid2=$!
db2 "Call PROC3" &
pid3=$!
# then only wait that every process has done
wait $pid1 # wait process to end af it already ended then continue to the next line
wait $pid2 # so no need to make any while waiting
wait $pid3
# or wait every together with one wait, wait exit after every process has ended.
wait $pid1 $pid2 $pid3
I tried this approach. Even though processes are created and i can see their PIDs. Still only one procedure is executing at a given time, the first one in sequence, followed by second and so on.
I believe only one procedure call is possible per DB Session.
Is there a way to make 3 seperate DB Sessions and run the procs one each in them.
This does create three separate sessions, by running db2 3 independent times.
If they are waiting for each other, there may be database locking involved and the like.
Or perhaps they are getting 'frozen' by attempting to interact with the user. They must be completely noninteractive to go in the background like this.
To verify locking part, I ran the procedures in three seperate unix sessions. They ran perfectly. So it cant be locking.
You also mentioned frozen for interaction with user.
I also added nohup to the procedure call commands, still result is same.
When I check in database also, it shows only one procedure running from that user, others are not even started.
Please show the code you tried which didn't work. Maybe there's a mistake we can fix. There's no reason except the code or the terminal that it'd get frozen, 'command &' does exactly what you want - put it in background.