I think this cuts to the heart of the matter. It's not that your parent is waiting for the child to finish, but that the Apache server is waiting for the output pipe from the CGI script to close, and the child process still has it open. Closing
STDOUT in the child should fix the problem. Try one of these:
system("perl script.pl >/dev/null &");
open(CMD, "|perl script.pl > /dev/null");
To illustrate that both the system and open methods will spawn a child process without blocking the parent, both of these scripts will continue to print "boo" even after the parent has exited:
system("while true; do echo boo; sleep 2; done &");
print "system done - exiting\n";
open(CMD, "|while true; do echo boo; sleep 2; done");
print "open returned - exiting\n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.