What exactly do you mean by "I don't want to build a listener in the parent." Clearly the parent has got to listen in some way. There are couple of ways to do non-network IPC. You can use basic pipes:
pipe(README, WRITEME);
if (fork) {
#parent code
while (<README>) {
# you can do other stuff in here besides reading
$output .= $_;
}
close(README);
} else {
# child code
print WRITEME "interesting stuff";
close(WRITEME);
}
There's also named pipes, which are nice in cases when there isn't a relationship between the communicating processes (although you could use them in this case if you want).
# writer
open(FIFO, "> /path/to/named.pipe");
print FIFO "Interesting stuff";
close(FIFO);
#reader
open(FIFO, "< /path/to/named.pipe");
while(<FIFO>) {
$output .= $_;
}
close(FIFO);
With named pipes, readers and writers will block until their counterpart appears at the other side unless you open the fifo using +<. All of these examples are out of the
Perl Cookbook, chapter 16.
Update: Forgot to mention you have to create the named fifo first, from the shell. On most systems this is
mkfifo /path/to/named.pipe
Older systems use mknod.
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.