I am using the below code to redirect a user to a webpage before the script has finished executing. The sample code below works fine.
defined(my $pid = fork) or die "Can't fork: $!"; if ($pid) { print "waiting"; waitpid($pid,0); print "done waiting"; } else { my $result= new CGI; print $result->redirect("redirection"); }
However, as you can see, I don't close the STDOUT or STDIN in the child process even though you are supposed to using the below code:
open STDIN, "</dev/null"; open STDOUT, ">/dev/null";
How big of a problem can this cause? Eliminating the above two lines seems to be the only way to get the output in a child process to output to the browser.

Someone also suggested that I print the rediretion in the parent process, then fork it, kill the parent process and let the rest of the script proceed in the child process. However, under this method, will I be able to catch the zombied child processes? Normally when you fork, you wait in the parent for the child to finish then continue. This way I'm killing the parent before the child finishes. Thanks.

In reply to forking efficiency by Anonymous Monk

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.