I may be missing something, but is there anything wrong with fork?
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
$|++;
print "Content-type:text/plain\n\nStarting script.....\n\n";
my $pid;
if (!defined($pid = fork)) {
die "Could not fork! $!";
}
elsif ($pid) {
# parent - clean up when child exits
1 while (waitpid($pid,WNOHANG) != -1);
cleanup();
exit(0);
}
else {
# child - does the processing
print "Processing...\n\n";
sleep(5);
print "Finished...\n\n";
exit(0);
}
sub cleanup {
# do the clean up here
}
In my test CGI $|++ doesn't seem to do anything. I can't work out why the output appears buffered - is that a fork side effect?
cLive ;-)