With these fixes, killed children at least are reported correctly for my setup.
Notes
HTH,
Peter
Update: Did this catch all errors :) ?
Update 2: appended the working variant above to track down remaining errors (+ /msg'ed).
use Data::Dumper; my %child_status=(); sub reaper { my $child; while (($child=waitpid(-1,WNOHANG))>0) { warn "signal: $child\n"; $child_status{$child} = $? >> 8; } } sub copy { my $file = shift; my $dir = shift; local $SIG{CHLD} = \&reaper; my $reader_pid = open( my $reader, '-|' ); if ($reader_pid) { } else { exec 'sleep 301'; exit; } my $writer_pid; if ($writer_pid = fork()) { } else { chdir($dir); open( STDIN, "<&=" . fileno($reader) ); exec 'sleep 302'; exit; } while (1) { sleep 1; next if !%child_status; print Dumper \%child_status; warn "r $reader_pid, w $writer_pid\n"; foreach my $pid ($reader_pid, $writer_pid) { if ($child_status{$pid} != 0) { %child_status = (); die "failed tar\n"; } } if (exists $child_status{$writer_pid} && exists $child_status{ +$reader_pid}) { last; } } } copy("/etc/hosts",".");
In reply to Re: Detecting when a child process is killed unexpectedly
by jakobi
in thread Detecting when a child process is killed unexpectedly
by rlb3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |