I have a concern whereby in a script, I will be calling parallel versions of a function to run in the background and then issuing a wait.
a () {
sleep $1
}
a 10 &
PIDs="$PIDs $!"
a 50000 &
PIDs="$PIDs $!"
wait $PIDs
The concern is the first function call takes 10 seconds (sleep 10), but the second takes nearly 14 hours (sleep 50000).
I am concerned the PID from the first invocation will be recylced and 14 hours later, when the second invocation is terminates, that PID is being used by another process and will prevent the script from continuing. Or does wait remove the first PID from the list as soon as that invocation completes and just simply waits for the second process to complete rather than waiting for both of them to finish at the end?