Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use Parallel::ForkManager;
- use constant MAX_CHILDREN => 3;
- {
- my $pm = Parallel::ForkManager->new(MAX_CHILDREN);
- my $pid;
- my @array1 = (
- 'The','silent','witness',
- );
- my $index = 0;
- pipe(FROM_CHILD,TO_PARENT) or print $!."\n";
- pipe(FROM_PARENT,TO_CHILD) or print $!."\n";
- select((select(TO_CHILD),$|++)[0]);
- select((select(TO_PARENT),$|++)[0]);
- for(my $i =0; $i <3; $i++){
- $pid = $pm->start() and next;
- print $array1[$index++%scalar @array1]."\n";
- $pm->finish();
- }
- $pm->wait_all_children;
- if($pid = $pm){
- print TO_CHILD "$index\n";
- chomp(my $child_says = <FROM_CHILD>);
- $index = $child_says;
- }else{
- chomp(my $parent_says = <FROM_PARENT>);
- }
- close(FROM_CHILD);close(FROM_PARENT);
- close(TO_CHILD); close(TO_PARENT);
- }
- OUTPUT
- The
- The
- The
- (then it hangs)
- Was hoping $index would be passed from child to parent and vice versa so it should print:
- The
- silent
- witness
Add Comment
Please, Sign In to add comment