The strace utility shows that, with child.pl's print omitted, main.pl is stuck in the wait4() system call, waiting for child.pl to exit and emit SIGCHLD. It seems that child.pl is not receiving SIGPIPE under those circumstances (proof below). Perhaps child.pl does not set up its end of the pipe, having nothing to say.

With the print statement in, strace shows that child.pl exits with SIGPIPE, just the way we expect.

Changing child.pl to,

#!/usr/bin/perl $SIG{PIPE} = sub { die 'SIGPIPE received' }; $| = 1; sleep 10; # print "x\n"; while (1) { sleep 10; }
does not change the behavior, so SIGPIPE is not received by child.pl. Restoring the print line yields the message,
$ ./main.pl
SIGPIPE received at ./child.pl line 2.
$ 

As ysth suggests, you could kill the child explicitly with SIGINT.

After Compline,
Zaxo


In reply to Re: How to end a process started with open "cmd |" before it has output by Zaxo
in thread How to end a process started with open "cmd |" before it has output by Crackers2

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.