I have some code that forks 15 processes, waits until they complete then prints up some html with some results. When i run it just from the shell it all runs as expected with 1 set of html coming out nicely. However when i run it from a web brower it gets the html 15 times kinda mushed together. My forking section is..
for ($count=0;$count<5;$count++){ unless (defined ($pid[$count] = fork)) { print "im dying\n"; die "cannot fork: $!"; } unless ($pid[$count]) { print "im a kid with pid $$\n"; `do my thing`; exit; #child stops ehre } } # Parent continues here
then after that i have the usual
print "Content-Type:text/html\n\n"; print $q->pre("Will be tracing to $trace<BR>\n"); print ("your coming from $ENV{REMOTE_ADDR}<BR>\n");
along with the rest of the html, not in a loop or anything and only starting after all child processes have finished. The output im getting in the brower is in the form of
1 1 2 1 2 3 1 2 3 4
where 1,2,3,4 are the first few lines of html. When run from the shell though it runs perfectly, this only happens in browsers.. is there something about the forking im missing? thanks Andre

In reply to CGI printing output x times, where x is the number of forks. by zedar

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.