Child processes writing to a "shared socket" is a Bad Thing, and is probably best avoided. Apache manages to do this, but only with some very careful signal handling and locking, and even then, Apache is only trying to distribute the listen/accept component.
I would suggest making a parent process which handles the multiplexing of the sockets. Like
perlipc recommends, you would create a
pipe between the parent and each child process, and then later, read these and forward anything read out the main socket. The parent just multiplexes and the children do the actual work.
Use
IO::Select and your job will be that much easier.
As a note, the reason you use
syswrite instead of
print is that
syswrite is unbuffered, always, regardless of $|. If your output is buffered, there are occasions where each process only writes a portion of a line, and this can make for bad output data, such as "AAAAAAAA\nBBBBBBBB\n" becoming "AAAABBBBBBBB\nAAAA\n".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.