I want to run 3 (or more) tasks in parallel and get an overall success code of 0 if all 3 tasks succeeded OR an overall success code of non-0 if any of the 3 tasks did not succeed (i don't need to know which one(s)). My current one works 'most' of the time, except when pid gets reused then i end up getting return code of some other random task.
f_wrapper a &
pids="$pids $!"
f_wrapper b &
pids="$pids $!"
f_wrapper c &
pids="$pids $!"
for pid in $pids; do
ps -f -w -p $pid
wait $pid
RETURNCODE="$?"
if [ $RETURNCODE -ne 0 ]; then
echo "RETURNCODE=$RETURNCODE for pid=$pid"
RESULT=1
fi
done
please no bash 4.3 answers, i am on 4.2
as per the comment in the 'duplicate q link': "That is still buggy. If the PID is reused, the exit code of wait will be non zero because you can only wait on childs of the current process which will make it look like one of the commands failed even if they didn't."