Cameron B. Prince wrote:

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.

most of them aren't needed (they don't exist in the Apache 2.0 API.


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.)

what open()? what's not working? please be more specific, show us some code and the actual error messages. Are you talking about open in
http://perl.apache.org/docs/1.0/guide/performance.html#A_Complete_Fork_Example
?


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.

have you detached the session as explained here? http://perl.apache.org/docs/1.0/guide/performance.html#Detaching_the_Forked_Process

I admit I haven't tried this code from the above url with 2.0 yet (and it'd be nice to have such a test (hint! hint!)) but I can't see it in your sample, so I assume that you haven't tried it ;)

Also while you are at it, once you figure out all the quirks if you can help us porting http://perl.apache.org/docs/1.0/guide/performance.html#Forking_and_Executing_Subprocesses_from_mod_perl to 2.0 docs that would be very helpful for those coming after you. Thanks.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



Reply via email to