For Win32 - ActiveState doesn't properly kill processes. use strict; use Cwd; use POSIX; use Data::Dumper; my %hashChildPids; # key = expiration timestamp my $child_ttl = 1; # The max time in minutes a child is allowed to live while (1) { my $pid; if ($pid = fork) { # Parent print "[PARENT $$]: I just forked $pid at " . time . "\n"; $hashChildPids{$pid} = ($child_ttl * 60) + time; # Give the ttl value my $pidCount; foreach my $kidPid (keys %hashChildPids) { $pidCount++; } print "[PARENT $$]: Known Number of Children of Parent: $pidCount\n"; #foreach my $cpid (@listPids) { # print "$cpid " #} #print "\n"; } elsif (defined $pid) { my $sleepCount=2; print ("[CHILD $$]: sleeping for $sleepCount seconds\n"); sleep $sleepCount; print ("[CHILD $$]: I'm awake and am about to exit.\n"); exit(); } else { print "cannot fork process: $!\n"; print "[PARENT $$]: Sleeping for 10 seconds\n"; sleep (10); } #print "Time = " . time . "\n"; #print Dumper(\%hashChildPids); foreach my $childPid (keys %hashChildPids) { if ($hashChildPids{$childPid} <= time) { print "[REAPER $childPid]: This child must die - $hashChildPids{$childPid}.\n"; my $status = waitpid($childPid, 0); print "[REAPED $childPid] $status $?\n"; delete ($hashChildPids{$childPid}); # Remove hash entry so we don't reap it again } } }