tags:

views:

61

answers:

2

I'm trying to fork 3 different child processes from a parent (and running this on a UNIX box), and I want to have this requirement :

The parent must wait till all the 3 children processes have finished executing.

I'm using wait for 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;
    /* ... */

At last, in the parent, I do this :

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

Question :

Do I need to call wait thrice or does a single call suffice? I need to know how this works..

+2  A: 

You have to wait three times.

Chris Jester-Young
+3  A: 

You have to issue three waits. Each wait blocks until a child exits or doesn't block if a child has already exited. See wait.

wallyk