Hello,
I have a question about pipes. In the following example, the parent blocks after sending 1024 pipe messages to the child because the child is not reading the messages. Is it possible to prevent this blocking behaviour and immediately return without blocking?
use strict;
use warnings;
use IO::Socket;
my $handle;
my $pid;
if (!defined($pid = open($handle, "|-"))) {
die "Fork failed: ".$!;
}
elsif ($pid == 0) {
# Child
sleep(5);
exit 0;
}
else {
# Parent
$handle->autoflush(1);
my $i = 0;
my $result;
do {
$result = print $handle "ABC\n";
print "PIPE write ".++$i."\n";
} while ($result);
}
I'm experiencing this in a large project where sometimes a child process is busy doing something which is not interruptable and therefore not able to read the pipe messages. The parent process needs to continue and not block. FYI, it is no problem that the pipe messages are lost, because they will be resend later.
Thanks in advance!