in reply to Multiprocess - child process cannot be finished successfully

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re: Multiprocess - child process cannot be finished successfully

Replies are listed 'Best First'.
Re^2: Multiprocess - child process cannot be finished successfully
by marto (Cardinal) on Sep 09, 2022 at 09:54 UTC
      for (my $index=0; $index <= $#$array; $index++){ defined(my $pid = fork) or die "fork failed: $!"; unless( defined($pid) ) { flock $logfile, LOCK_EX; print $logfile "OK $!\n"; flock $logfile, LOCK_UN; } unless($pid) { # child print "child: $$\n"; eval { ....... }; if( $@ ) { flock $logfile, LOCK_EX; print $logfile "ok"; flock $logfile, LOCK_UN; } unless( .. ) { flock $logfile, LOCK_EX; print $logfile "ok"; flock $logfile, LOCK_UN; else { flock $fh, LOCK_EX; print $fh "ok"; flock $fh, LOCK_UN; } close($fh); close($logfile); exit; # exit child process } if(wait() == -1){ print "Parent Process"; close($fh); # Close file handler $fh close($logfile); # Close file handler $logfile rename ($oldfilename, $newfilename) or die "Error in renaming $!"; + alarm(0); } }