sub _run_run3 { my ( $self,$xargs,$type ) = @_; $self->{'logger'}(DEBUG,"_run_run3 (parent) have pid $PID"); if ( _get_runnings() > $self->{'cfg'}->{'max_run'} ) { $self->{'logger'}(2,'max count of running jobs reach, skip current new job'); $self->_cleanup_process_list(); return ; } my $idx = _get_index_name ( $type,$xargs ); $self->{'logger'}(0,"_run_run3 type $type $xargs->{$type . '_name'}"); if ( defined $self->_is_running($idx) ) { $self->{'logger'}(0,"_run_run3 skip $type $xargs->{$type . '_name'} , still running"); return 2; } my @run = ("$xargs->{'run'}"); if ( defined $xargs->{'arguments'} ) { push @run,$xargs->{'arguments'}; } my $kpid = $daemon->Fork(); if ( not defined $kpid ) { croak "can\'t fork(run3), $ERRNO"; } elsif ( $kpid > 0 ) { # parent # Register PID $STARTEDCHILD{$kpid} = $idx; $self->{'logger'}(DEBUG,"_run_run3 (parent) have pid $PID"); $self->{'logger'}(0,"_run_run3 type $type $xargs->{$type . '_name'} forking child PID $kpid") ; } else { # child my ($run3_exit_code,$eval_run3_err); if ( defined $xargs->{'catch'} ) { $self->{'logger'}(DEBUG,"_run_run3 (child) have pid $PID"); $self->{'logger'}(DEBUG,'_run_run3 catch option active'); $eval_run3_err = eval { run3(\@run,undef,\*STDOUT,\*STDERR) ; $run3_exit_code = $CHILD_ERROR ; }; } else { run3(\@run,undef,\*STDOUT,\*STDERR); $run3_exit_code = $CHILD_ERROR ; } $self->{'logger'}(1,"_run_run3 $PID $xargs->{$type . '_name'} process done, with code $run3_exit_code"); exit $run3_exit_code; } my $xpid = waitpid FALSE, WNOHANG; if ($xpid > 0) { my $exit_code = $CHILD_ERROR ; # /SHIFTERR; my $worker_id = $STARTEDCHILD{$xpid}; if ( defined $worker_id ) { $self->{'logger'}(1,"_run_run3 child process $worker_id finish with exit $exit_code" ); } else { $self->{'logger'}(1,"_run_run3 child process $xargs->{$type . '_name'} finish with exit $exit_code" ); } return $exit_code; } return; }