http://qs321.pair.com?node_id=11142787


in reply to Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end?

The direct answer to your question is that the filehandles which form the connection to the web client get duplicated in the child, so the connection doesn't get closed until both the parent and child have closed the filehandles. So normally the parent would fork, the child would immediately close any filehandles it shares with the parent, then go off and do its thing. In the meantime the parent handles doing any HTML output then quits.

Note that you show both the parent and child outputting the headers, which is wrong.

But more generally this arrangement is likely to be a bad idea. It's very easy for someone to maliciously or inadvertently send many short requests to the web server, which results in thousands of long-running forked processes vying for memory and CPU.

Dave.

  • Comment on Re: Can I have a Perl script, initiated from a browser, fork itself, and not wait for the child to end?