in reply to How to send & receive data to many child processes?

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        

  • Comment on Re: How to send & receive data to many child processes? (one pipe)

Replies are listed 'Best First'.
Re^2: How to send & receive data to many child processes? (one pipe)
by vancetech (Beadle) on Mar 10, 2006 at 08:32 UTC
    Yah perfect, that works as expected. Thanks tye!
Re^2: How to send & receive data to many child processes? (one pipe)
by perrin (Chancellor) on Mar 10, 2006 at 18:27 UTC
    Nice idea and explanation, tye. Thanks.