How to wait for three child processes?

I am trying to develop 3 different child processes from a parent (and run this in a UNIX box) and I want to have this requirement:

The parent must wait for all three child processes to complete.

I use waitfor the same. Here's the code snippet:

#include <unistd.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    int stat;
    /* ... */

Finally, in the parent, I do this:

    wait (&stat);
    /* ... */
    return 0;
}

Question:

Do I need to call waitthree times or is one call enough? I need to know how this works.

+3
source share
3 answers

You have to wait three times.

+2
source

. wait , , . . wait.

+3

Side note: if you do not want to block waiting for each of them to complete, you can instead set up a signal handler for SIGCHLD and then call wait () to get the return code if you know that it is ready.

0
source

Source: https://habr.com/ru/post/1732278/


All Articles