Howto spawn multiple child processes and wait?

As far as I can tell, the bash wait command waits for a logical "AND" of all the child processes.

Assuming I am coding in C:

(1) What is the function I would use to create multiple bash child process running perl?

(2) What is the function I would use to reinvent the bash wait command so I could wait for a logical "OR" so my parent wakes up when the first child process dies?

Thanks,
Siegfried

From the man page of wait(2) - HP-UX,

The wait syscall will return for each of the children seperately, so you will have to issue the call as many times as there are children. Alternately, you could look into signal handling as the parent process receives a SIGCHLD when one of the children terminate.

but with a name like "wait", I assume the calling will be blocked until child dies. Correct?

It sounds like what you are describing is a serial approach and I want a parallel approach where all the children are executing in parallel.

Or perhaps I misunderstand...

Thanks,
Siegfried

How would I block with signal handling? Would I have to poll and then sleep and then poll?

What is the name of the function to call so I can block until receiving a signal?

Thanks,
Siegfried

Your code can have all the children executing in parallel. Write it such that the main parent process will fork children till there are no more left to fork, and then start wait()ing. The execution of the children will be parellel in this case, but the parent process will issue the waits in a serial manner.

Check the man pages for sigaction and signal.