The code you wrote looks to me like it'll work only as long as the connection created in your IO::Socket::INET command stays up.
If a network outage occurs, if the remote end closes the connection,
or if the person or script sending input to your script via STDIN closes the pipe,
then one of your while() loops will finish and the corresponding process will die.
Also: as it is now, if your child dies (remote connection close) but your STDIN keeps coming, the parent process will live on indefinitely, but it won't work very well.
You could try to wrap the entire thing in a while (1) loop, but that wouldn't fix the problem
of one process living on once the other exits. One way to fix this is to make sure the parent process is the one which exits its loop most often,
and then to have it kill off its child process after the loop exits, since it knows its child's pid.
Without seeing what you're doing in the while loops it's hard to tell whether this is the best way to do what you want. Be aware that after you fork(), you can't share new variable values
between the parent and child processes. Your idea to share data through files can
work, but beware of deadlock.
Alan
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.