use strict; use warnings; use IPC::Shareable; my ( $glue, $options ) = ( 'data', { create => 1, exclusive => 0, mode => 0644, destroy => 1, }); tie my @data, 'IPC::Shareable', $glue, $options; if ( ! defined ( my $pid = fork() ) ) { die "Cannot fork!: $!"; } elsif ( $pid == 0 ) { # Child my $item; sleep 1; for ( my $i = 1; $i <= 10; $i++ ) { ( tied @data )->shlock; $item = shift @data; ( tied @data )->shunlock; $item = '' if ( ! defined $item ); print "Child: $item\n"; } } else { # Parent for ( my $i = 1; $i <= 10; $i++ ) { ( tied @data )->shlock; push @data, $i; ( tied @data )->shunlock; print "Parent: @data\n"; } waitpid( $pid, 0 ); } #### Parent: 1 Parent: 1 2 Parent: 1 2 3 Parent: 1 2 3 4 Parent: 1 2 3 4 5 Parent: 1 2 3 4 5 6 Parent: 1 2 3 4 5 6 7 Parent: 1 2 3 4 5 6 7 8 Parent: 1 2 3 4 5 6 7 8 9 Parent: 1 2 3 4 5 6 7 8 9 10 Child: 1 Child: 2 Child: 3 Child: 4 Child: 5 Child: 6 Child: 7 Child: 8 Child: 9 Child: 10