Here's a version that uses that SIGPIPE to restart a child ( with a new pipe ), but things had to be shuffled around a bit.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1174747 use strict; use warnings; $| = 1; my ($from_parent, $to_child ); while(1) { my $msg = "hello from $$\n"; print "pipe and fork, parent $$\n"; pipe( $from_parent, $to_child ) or die "$! on pipe"; if( my $pid = fork ) { # parent close $from_parent; my $more = 1; $SIG{HUP} = sub { $pid and kill 15, $pid }; $SIG{PIPE} = sub { $more = 0 }; while($more) { syswrite $to_child, $msg, length $msg; sleep 3; } } elsif( defined $pid ) { # child close $to_child; print "child $$ started\n"; while(1) { if( sysread $from_parent, my $buffer, 100 ) { print "in child $$: $buffer"; } } exit; } else { die "$! on fork"; } }

In reply to Re: fork(): terminating the child without killing the parent by tybalt89
in thread fork(): terminating the child without killing the parent by Bloehdian

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.