'Using wait for multiple processesing

I am trying to automate a job with a shell script and in the process, I launch multiple jobs as follows:

for iproc in $( seq 1 $NPROC); do
> mybinary.x $iproc &
> done

How can I use wait to check for all these processes to return their exit status and move go to the next step?

I tried using wait -f but that I guess that only waits for the last of the process launched from the loop. But, I want to wait for all the process being launched to reach completion and relaunch if some of them end abruptly.

Ideally, if a child process dies with some error, I would also like to relaunch that particular job by getting the pid for that procees with something like pid=$(pgrep 'mybinary.x $iproc').



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source