I'm studying parallel processes and would like all child processes to send some messages to parent process. But I do not understand is it possible to do it via one pipe, or there should be separate pipes for each child process. Also, messages are being delievered to parent process just one time. Could you please advice how to fix it?
Thank you in advance!
#!/usr/bin/perl #use strict; #use warnings; use IO::Handle; pipe (READER, WRITER); WRITER->autoflush(1); my $parent=$$; print "parent: $parent\n"; # Forking childs for (my $count = 0; $count < 2; $count++) { defined (my $pid = fork) or die "Cant fork: $!"; } if ($$ == $parent) { # Master process while (1) { print "parent $$\n"; close WRITER; chomp (my $line = <READER>); print "<<<<<<<<<<<<<<<<<<<$line\n"; close READER; sleep 2; } } else { # Fork process while (1) { print "\tchild $$\n"; close READER; print WRITER "$$"; close WRITER; sleep 1; } exit 0; }
In reply to Getting messages from child processes via pipes by Frizoker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |