Hi Monks-

Consider the attached script.

I believe I should get 2 lines of output from each of the 2 children. Running this under perl, v5.8.8 built for darwin works fine. However, when I run it under perl, v5.8.8 built on solaris, strange things happen:

TRY1: CHILD1: My pid = 21727 CHILD1: 1: THIS IS YOUR PARENT SPEAKING... CHILD1: 2: THIS IS YOUR PARENT SPEAKING... CHILD1: 1: THIS IS YOUR PARENT SPEAKING... CHILD1: 2: THIS IS YOUR PARENT SPEAKING... CHILD2: My pid = 21728 CHILD2: 1: THIS IS YOUR PARENT SPEAKING... CHILD2: 2: THIS IS YOUR PARENT SPEAKING... TRY2: CHILD1: My pid = 22218 CHILD1: 1: THIS IS YOUR PARENT SPEAKING... CHILD1: 2: THIS IS YOUR PARENT SPEAKING... CHILD2: My pid = 22219 CHILD2: 1: THIS IS YOUR PARENT SPEAKING... CHILD2: 2: THIS IS YOUR PARENT SPEAKING... CHILD2: 1: THIS IS YOUR PARENT SPEAKING... CHILD2: 2: THIS IS YOUR PARENT SPEAKING...
First, why do I sometimes get 4 lines from one “bad” kid??

Second, why does the “bad” kid sometimes change?

Any pointers very much appreciated!

Thanks

-Craig

#!/opt/exp/bin/perl use strict; use warnings; foreach my $i (1..2) { _spawn($i); } sub _spawn { my $id = shift || die "Missing id\n"; my $pid = fork(); defined $pid or die "bad open (pipe/fork): $!\n"; # Have parent/child run their respective code... if ( $pid ) { # PARENT CODE... return; } else { # CHILD CODE... print "CHILD$id: My pid = $$\n" ; while(<DATA>) { print "CHILD$id: $_" }; exit } } __DATA__ 1: THIS IS YOUR PARENT SPEAKING... 2: THIS IS YOUR PARENT SPEAKING...

In reply to Stuttering Children by cmv

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.