use strict; use warnings; use IPC::Shareable; my $options = { create => 1, exclusive => 0, mode => 0644, destroy => 1, }; tie my $cntr, 'IPC::Shareable', $options; my $val; $cntr = 0; if ( ! defined ( my $pid = fork() ) ) { die "Cannot fork!: $!"; } elsif ( $pid == 0 ) { # Child for ( 1 .. 10000 ) { ( tied $cntr )->shlock; $val = $cntr++; ( tied $cntr )->shunlock; } } else { # Parent for ( 1 .. 10000 ) { ( tied $cntr )->shlock; $val = $cntr++; ( tied $cntr )->shunlock; } waitpid $pid, 0; print "counter: ", $cntr, "\n"; }