#!/usr/bin/perl -w use strict; my %hash; my $href = \%hash; my @list = qw/1 2 3 4 5 6/; my $pid = fork; if ($pid) { #parent print "$$: Parent Pid\n"; my $new_child = fork; unless($new_child) { #child 1 while (1){ hash_check($href); sleep 3; } exit; } } else { #child 2 for (@list){ pinger($href,$_); } } 1 while waiter(); sub hash_check{ my $hash = shift; print "~~~~~~~~~~~~~~~~~~\n"; for (keys(%$hash)){ print "Key is $_\n"; } print "~~~~~~~~~~~~~~~~~~\n"; } sub pinger{ my $hash = shift; my $value = shift; #print "$$: pinger\n"; if ($value < 4){ add_to_hash($hash, $value); } } sub waiter{ my $waited_pid = wait; # print $waited_pid,"\n"; } sub add_to_hash{ my $hash = shift; my $failed_addr = shift; $$hash{$failed_addr} += 1; } sub del_from_hash{ my $hash = shift; my $pinged_ip = shift; delete $$hash{$pinged_ip}; }