I've been following this just at a high level, so if I'm posting a method
that you've already tried and dismissed please forgive me.
You can try forking followed by separating from the parent session. I
think that will help keep your program from getting killed when apache is
restarted or stopped.
use POSIX;
# FORK
$pid = fork;
if (not defined $pid) {
# unable to fork
} elsif ($pid) {
# parent to exit, child continue
exit 0;
}
# Separate from parent
$status = 0;
POSIX::setsid() or $status = "Couldn't start new session: $!";
if ($status) {
# unable to separate from parent session
} else {
# searated from parent
$status = 0;
}
On Fri, 12 Sep 2003, Cameron B. Prince wrote:
> Hi all...
>
> Sorry about the previous message getting screwed up... Not sure what
> happened...
>
> I have a report generator program written in Perl that I need to start from
> a CGI. The program takes about 15 minutes to run, so I must fork or double
> fork. I have two goals:
>
> 1) Have no zombies when the program completes
> 2) Fork in such a way that restarting Apache doesn't kill the forked
> process.
>
> I tried out the code here which is for mod_perl v1:
>
> http://perl.apache.org/docs/1.0/guide/performance.html#Forking_and_Executing
> _Subprocesses_from_mod_perl
>
> There are two problems with the code listed in the example:
>
> 1) Apache::SubProcess doesn't seem to contain the same methods as the older
> version.
> 2) open isn't working. (I've already been down this road and switched
> another call to an external program to use IPC::Run, but that program
> doesn't take long and needs no fork.)
>
> I took out the parts of the code that caused problems and ended up with
> this:
>
> $SIG{CHLD} = 'IGNORE';
> defined (my $pid = fork) or die "Cannot fork: $!\n";
> unless ($pid) {
> exec $command;
> CORE::exit(0);
> }
>
> This works and accomplishes my first goal, but not the second. If I start
> the program and restart Apache, the program is killed.
>
> Does anyone have ideas as to how to solve this?
>
>
> Thanks,
> Cameron
>
>