Monks,

There are three processes.

  1. The parent
  2. A child that cats a tarball to stdout. A reader
  3. A child that redirects STDIN to the other child and untars the stream from that child. A writer

What I am having trouble with is getting the parent to detect if the writer has exited early. So if I start it running get the pid of writer and kill -9 that pid SIGCHLD doesn't seem to be executed. If the reader is killed SIGCHLD is executed.

I don't understand what is going on. Why isn't SIGCHLD signaling when I kill the writer.

use Data::Dumper; my %child_status; sub reaper { my $child; while (($child=waitpid(-1,WNOHANG))>0) { $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 '/bin/cat', $file; exit; } my $writer_pid; if ($writer_pid = fork()) { } else { chdir($dir); open( STDIN, "<&=" . fileno($reader) ); exec '/bin/tar', '-x', '-p', '-f', '-'; exit; } while (1) { sleep 1; next if !%child_status; foreach my $pid ($reader_pid, $writer_pid) { if ($child_status{$pid} != 0) { print Dumper \%child_status; %child_status = (); die "failed tar\n"; } } if (exists $child_status{$writer_pid} && exists $child_status{ +$reader_pid}) { last; } } }

Thanks for any help you can give...


In reply to Detecting when a child process is killed unexpectedly by rlb3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.