I was trying that but I can't seem to make it work. I kill (-15) the parent but the child carries on regardless. I have made the parent the reader and child the writer and have tried it the other way around. I'm using a short sleep in a loop in the child to mimic periodic activity. Using Perl 5.8.4 on SPARC/Solaris 9. Here's the script.

use strict; use warnings; use IO::Pipe; $SIG{PIPE} = sub {exit;}; print qq{Parent PID $$\n}; my $pipeFH = IO::Pipe->new(); my $pid; if ($pid = fork) { $pipeFH->writer(); print qq{Kid is PID $pid\n}; } elsif(defined($pid)) { $pipeFH->reader(); sleep 1 for 1 .. 100; exit; } while ((my $returnPid = wait) != -1) { print qq{Kid $returnPid returned\n}; }

Maybe there is a flaw in my attempt.

Cheers,

JohnGG

Update: The flaws in my attempts were twofold. Firstly, frodo72 pointed out that the SIGPIPE would not be generated until the child process tried to do I/O on the pipe that had been closed at the other end because the parent had been killed. Secondly, it appears that IO::Pipe is somehow consuming the SIGPIPE before the child sees it so the child carries on oblivious to it's parent's death. Again, frodo72 discovered this by refactoring my code to use pipe instead of IO::Pipe.

frodo72 ++ and thanks for all the help.


In reply to Re^2: Child process dies by johngg
in thread Child process dies by dejans

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.