$SIG{'ALRM'} = 'sig_handler'; setitimer(ITIMER_REAL, 1, 10); while (1){} sig_handler{ if ($pid = fork){ }else{ my $MAX = 1000; # just for testing my $pm = new Parallel::ForkManager($MAX); my $dbh = DBI->connect("DBI:mysql:database=xxxxxx;host=SOMEHOST", "user", "passwd", {'RaiseError' => 1}); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; my ($check_id, $host) = $ident =~ /^(.*?) on (.*)/s; insert_result(\$dbh, $host, $check_id, $exit_code); } ); $pm->run_on_start( sub { my ($pid,$ident)=@_; print "** $ident started, pid: $pid\n"; } ); for(my $i=0; $i< @servers; $i++){ my $srv_id = $servers[$i]{id}; my $srv_name = $servers[$i]{name}; for my $check_id (@{$checks{$srv_id}}){ $pm->start("$check_id on $srv_id") and next; exec(@{$commands{$check_id}}); print(STDERR "$check_id on $srv_name exec failed: $!\n"); _exit($!); } } $dbh->disconnect(); exit(); } }