use warnings; use strict; use IPC::Shareable; $SIG{INT} = sub { exit; }; my $href = {count => 0}; my $ipc = tie $href, 'IPC::Shareable', undef, { destroy => 1 }; for (1 .. 3) { unless (fork()){ while (1){ $ipc->shlock(); $href->{count}++; $href->{pid} = $$; $ipc->shunlock(); } exit; } } while (1) { next if ! defined $href->{pid}; print "pid: $href->{pid}, count: $href->{count}\n"; sleep 1; } #### pid: 19062, count: 1 pid: 19062, count: 1472 pid: 19063, count: 3070 pid: 19063, count: 4771 pid: 19062, count: 6548 pid: 19062, count: 8179 pid: 19062, count: 10070 pid: 19064, count: 11817 ^C