Hello -
Please take a look at the code below (it can be invoked on my site via
http://www.marcfest.com/temp/fork.cgi).
When running the program in the linux shell it dumps its output right
away, without waiting for the child process ("sleep 10") to complete.
When invoking it through the browser, though, it does not send its
output to the browser until the child process is completed.
How do I fix that? I want it so that when invoked through the browser
the scripts prints the output and terminates the browser connection
immediately while then finishing the child process in the background.
As a solution to his question please post a revision of the script
that will work as described above.
Thank you for helping.
Marc.
####################################################
#!/usr/bin/perl -w
my $time = time;
$| = 1;
print "Content-type: text/plain", "\n\n";
print "$time We are about to create the child!", "\n";
defined(my $childpid = fork) or die "Cannot fork: $!";
if ($childpid) {
print <<End_of_Parent;
I am the parent speaking. I have successfully created a child process.
The Process Identification Number (PID) of the child process is: $childpid.
The child will be cleaning up all the files in the directory. It might
take a while, but you do not have to wait!
End_of_Parent
exit;
} else {
#this is the child process
open STDIN, "</dev/null";
open STDOUT, ">/dev/null";
sleep 10;
exit(0);
}
########################################### |