I recently had a problem using (pipe | -) when I wanted to establish a connection between two processes. Basically, the child process could not process the STDIN as fast as it was populated by the parent. This made the parent wait until STDIN became free and made it slow.
How big can an STDIN be, and is it possible to modify it. If so, what is the size of the best practice?
Here is a sample code to show what I mean:
if ($child_pid = open($child, "|-"))
{
$child->autoflush(1);
while (1)
{
process_packet($packet);
print $child $packet;
}
}
else
{
die "Cannot fork: $!" unless defined $child_pid;
my $line;
while($line = <STDIN>)
{
chomp $line;
another_process_packet($line);
}
}
In this example, another_process_packetslower than process_packet. The reason I write this code is because I want to use the same data from the socket and actually get it once.
Thanks in advance.