I found some code that 2 processes in Perl can communicate via a pipe. Example:
if ($pid = fork) {
close $reader;
print $writer "Parent Pid $$ is sending this\n";
close $writer;
waitpid($pid,0);
}
else {
close $writer;
chomp($line = <$reader>);
print "Child Pid $$ just read this: `$line'\n";
close $reader;
exit;
}
Now I have the following questions:
- Is it possible to make the reader read from the pipe, and then block until new data come from the pipe like in a loop?
- If yes what is the way to kill the child process when the parent process has no data to send?
- Is there a limitation on how many open read/write pipes I have per program? E.g. if I fork 10 processes and have 20 pipes (10 read/10 write) is it a bad idea?
I am sorry if the questions are too basic but my experience is with threads in another language.