Why the sleep 1 for 1 .. 100;? My ignorance really; I wasn't sure whether the script, like my daughter, would sleep through the alarm so I decided to try lots of small sleeps after it didn't work with one long sleep.

I was already trying things like explicitly closing the pipe in the parent if it caught a signal. Following your post I have modified the script so the child keeps printing a "heartbeat" to the pipe but still to no avail. Here's the modified script.

use strict; use warnings; use IO::Pipe; my $pipeFH; my $rcHandler = sub {$pipeFH->close(); exit;}; $SIG{INT} = $rcHandler; $SIG{QUIT} = $rcHandler; $SIG{TERM} = $rcHandler; print qq{Parent PID $$\n}; $pipeFH = IO::Pipe->new(); my $pid; if ($pid = fork) { $pipeFH->reader(); print qq{Kid is PID $pid\n}; } elsif(defined($pid)) { $SIG{PIPE} = sub {exit;}; $pipeFH->writer(); $pipeFH->print(qq{Kid: Snoozing\n}); for my $heartbeat ( 1 .. 30 ) { $pipeFH->print(qq{Kid: Heartbeat $heartbeat\n}); sleep 1; } $pipeFH->print(qq{Kid: Waking\n}); print qq{Kid: Quitting\n}; exit; } while ((my $returnPid = wait) != -1) { print qq{Kid $returnPid returned\n}; } while (defined(my $line = $pipeFH->getline())) { print qq{Read: $line}; }

I had been killing the parent with a kill -15 (TERM) from another shell but I noticed that the child does go away immediately if I Ctrl-C the running parent. Is it the case that child processes also get an INT if the parent gets one from the shell?

Cheers,

JohnGG


In reply to Re^4: 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.