I am sure there is more than one way to do this. But I've put some pseudo-code down here, as to how it might be done.
Basically, I've decided to store the pid of each backgrouded curl command in an array, and to periodically poll each process pid with a kill -0 command, to see if it still running. And if not, then the nextcurl() function will be called, to start up the next curl command.
Furthermore, I suspect that backgrounded processes do not always die when their parent is killed. So a trap function may be necessary here too.
Its all quite rough and untested, bad-habits and errors in there, no doubt.
Code:
# Run next curl command. $1 = the job number
nextcurl() {
foo=$1
# Generate and run your next curl command. Pseudo-code.
curl command1 1>/dev/null 2>&1 & # disown
# Store the backgrounded curls pid number
pidx[$foo]=$!
}
pidx=( 0 0 0 )
# Some kind of trap function may be needed here, to ensure that
# all children processes are killed at exit.
trap ' for numx in "${pidx[$@]}" ; do kill $numx ; done ; exit ; ' INT
# The pids of running curls are each tested, to see if they are still running. If not,
# then the nextcurl function is called, to restart the next curl command
while :
do
for varx in {1..3} do
if [[ ${pidx[$varx]} -eq 0 ]] || ! kill -0 ${pidx[$varx]} 1>/dev/null 2>&1
then
nextcurl $varx
fi
done
sleep 1
done