#! /usr/bin/perl -w use strict; $SIG{CHLD} = \&REAPER; my @server_list = qw/one two three four/; my $children = 0; foreach my $server (@server_list) { print "$$ Forking for server: $server\n"; if (my $pid = fork) { # Parent process # Nothing to do except go to the next server in the list $children++; sleep 2; next; } else { # Child process # Note that you *must* use 'exit;' when processing is # finished or the child will continue going through the # loop print "$$ Processing for server: $server\n"; sleep 3; exit; } } # Wait for children to finish while ($children > 0) { sleep; } sub REAPER { my $pid = wait; print "Process $pid has done it's stuff!\n"; $children--; }