in reply to Re: Re: Robustly piping several processes.
in thread Robustly piping several processes.

BazB and I had some very interesting discussions on and off, in the chat room, and through MessageBox, now we come to an agreement that, the pipe() function introduced in perlipc would be a good solution to connect IO handlers between processes.

He suggested me to post a reply to complete this thread, and I am doing so now. A piece of sample attached:
use IO::Handle; use strict; $| ++; pipe(PARENT_READER, CHILD_WRITER); pipe(CHILD_READER, PARENT_WRITER); PARENT_WRITER->autoflush(1); CHILD_WRITER->autoflush(1); my $pid; if ($pid = fork()) { close(CHILD_READER); close(CHILD_WRITER); my $buffer; print PARENT_WRITER 1; while (1) { sysread(PARENT_READER, $buffer, 100); print "parent revd: $buffer, and reply with ", $buffer + 1, "\ +n"; sleep(1); print PARENT_WRITER $buffer + 1; } } else { close(PARENT_READER); close(PARENT_WRITER); my $buffer; while (1) { sysread(CHILD_READER, $buffer, 1000); print "child revd: $buffer, and reply with ", $buffer + 1, "\n +"; sleep(1); print CHILD_WRITER $buffer + 1; } }