I'd just use a single pipe for sending out the tasks. Each child does a (blocking) read on the pipe when it is ready for the next task and exactly one child will get it (since the task data is smaller than the "system buffer size" -- likely 4KB).
That way the parent process doesn't have to do any selecting or managing; it simply writes each task to the pipe.
If you want to track the status of each child as well, I'd just have a second pipe that the children write messages to, including their own PID. To make things simple, I'd use one process for writing the tasks to the first pipe and another for reading status from the second pipe. Then no non-blocking I/O is needed.
I'd actually use two named pipes so that spawning new worker children or replacing either of the two manager processes becomes trivial.
- tye
In reply to Re: How to send & receive data to many child processes? (one pipe)
by tye
in thread How to send & receive data to many child processes?
by vancetech
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |