Then use the method I outlined. It is quite simple as far as IPC goes. You could use one of the IPC modules but I think they mostly subtitute one kind of complexity for another in this case rather than actually making things a lot simpler.

It boils down to the basic, typical use of fork and pipe. Parent creates pipe then forks N times. Parent closes read-from side of pipe and each child closes write-to side of pipe. Then parent can write small packets (each packet needs to be send via a separate syswrite, which you can accomplish by just turning on buffer auto flushing for the pipe filehandle and being sure to write the packet with a single print or similar) and each child can read from the pipe and atomically get the next packet and each packet will only go to one child.

I doubt it would be 2 dozen lines of code.

Parent should likely wait for each child after it has finished writing to and closeing the pipe (so it might want to save up the list of PIDs from forking, but it doesn't actually have to).

Each child boils down to a very simple close WRITE_TO; while( <READ_FROM> ) { doStuff( $array[$_] ) }.

- tye        


In reply to Re^5: Forking problem (manager) by tye
in thread Forking problem UPDATED by avi_learns_perl

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.