Each call of wait(2)
blocks the parent-process untill one of its children exits. So if you want to block the parent-process untill all children exit, you have to call wait()
in a for loop as many times as your children processes are.
while (wait(NULL) > 0)
won't work because wait()
returns the PID of the child-process caught, so it's always true, causing an infinite loop.