our %procs; use constant LIMIT => 4 $pm->run_on_wait(\&term_process, 1); $pm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; my ($check_id, $host) = $ident =~ /^(.*?) on (.*)/s; print("run_on_finish: $ident (pid: $pid) exited with code: [$exit_code] host: [$host]\n"); delete $procs{$pid}; print("proc_mgmt: $ident: deleting (pid: $pid) from list\n"); } ); $pm->run_on_start( sub { my ($pid,$ident)=@_; print("** $ident started, pid: $pid\n"); $procs{$pid} = time(); } ); sub term_process{ my $debug_time; my $total_time; while (my ($pid, $started_at) = each %procs) { next unless time() - $started_at > LIMIT; $debug_time = time(); $total_time = $debug_time - $started_at; print("[$pid] hung. time now: [$debug_time] - [$started_at] = [$total_time] sending KILL."); kill TERM => $pid; delete $procs{$pid}; } }