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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.