I have the following section of code that supposedly opens a bunch of child processes by piping:
$| = 1; $pid = open(first_child, "-|"); if ($pid) { while(<first_child>) { if ($_ =~ m/^Error/) { } #do nothin elsif ($_ =~ m/^Hits/) { push (@hits, $_) ; } else { push (@line, $_); } } } else { my (@child, @cpic); foreach $i(0..@gets) { $e = $gets[$i]; $c = $searches{$e}{handler}; $p = $FORM_DATA{p}; $q = $FORM_DATA{q}; $u = $searches{$e}{url}; $caller = "perl $c $p $q $u"; $cpid[$i] = open($child[$i], "|-"); if ($cpid[$i]) { } # do nothing else { system ($caller); exit; } } foreach (@child) { close($_); } exit; }
Now, this seems to be working properly, as I get all my data just fine. But now I've added something new to each of the called perl programs, a sub-call to another program. The line in each program will look like:
$more = 'perl makemore.pl "$words" "$keywords"';
The program makemore.pl seems to work just fine as it is. My problem is with data being pushed to the @hits array. It seems that when I comment out the perl call in the called programs, I get all my data in @hits just fine. But, with the line activiated, I'm getting some problems with some of the called programs not pushing their data into @hits.

This would be annoying enough, but the problem seems to be unrelated to anything I can see. As the processes are split off, their running time may vary. As such, the order of the results being returned may not always be the same. Another problem is that if I run just one sub-process in the loop above, it does work ok. In fact, I can sometimes run multiple sub-calls. The problem is that in some cases, running multiple sub-calls seems to blow away that one piece of the data. Other data from the sub-calls do come back just fine.

Addendum:

This is no longer a 2-pipe situation, as I've made the change to forking the the child processes off from the first pipe.

Other ideas in here I have tried, but they don't provide any further help. ForkManager isn't an option, as we don't have it installed here.

Also, when I set  $| = 1; I can see the output as it forms line by line. I can see that it's taking a second or 2 to generate the lines of output from @hits. But even then, it's still managing to skip one.

Read This !!!: After significant debugging with the help of someone who is much more foo in those ways than I, it has been discovered that the smashing up of my output has come from corrupted data, nothing more. So, I thank all of you who have given input. In the end, my coding will be better for this. And I have a few new ideas to mull over in my head. End result, the entire process is being redesigned almost completely from scratch to hopefully better account for the poorly formated data.

Again, thanks to all who have responded, please don't hate me for this. :)


In reply to Processes clobbering each other by mcogan1966

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.