in reply to Re: fork/exe, system open etc.
in thread fork/exe, system open etc.

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";

Replies are listed 'Best First'.
Re^3: fork/exe, system open etc.
by almut (Canon) on May 02, 2008 at 20:04 UTC
    It's not that your parent is waiting for the child to finish, but that the Apache server is waiting...

    You're absolutely right, I should've said grandparent (from the child's perspective)... Of course it's the Apache process which hangs waiting for the long-running process to close the pipes that were duplicated by the fork.

Re^3: fork/exe, system open etc.
by martino (Initiate) on May 06, 2008 at 08:09 UTC
    Brilliant, and yet so simple. It makes me wonder why it's not discussed in any of the documentation i've read (unless, of course, i'm reading the wrong documentation). Thanks pc88mxer.