Hi Richard,

> IMHO, it would be better to put your report code into another perl
> program and execute it.  From what I see from your snippet of
> code, it's
> not important for the parent to know what the child is going, you are
> even ignoring SIGCHLD.
>
> Also, at some point in the future (I hope at least) mp2 +
> threaded mpm's
> will become more than alpha (although I already use it extensively but
> I'm crazy) and you might want to run you code in it.  Forking under
> these circumstances would be a bad.

Thanks for you reply. The report code is in another perl program that I'm
trying to execute. The code I included below was from the v1 docs:

http://perl.apache.org/docs/1.0/guide/performance.html#Forking_and_Executing
_Subprocesses_from_mod_perl

Here is the code I ended up with:

   $SIG{CHLD} = 'IGNORE';
   defined (my $pid = fork) or die "Cannot fork: $!\n";
   unless ($pid) {
      exec $command;
      CORE::exit(0);
   }

This seems to work and no zombies are floating around. But I've not been
able to restart Apache while the forked program is running yet to see if
it's killed.

More comments or ideas welcome.

Thanks,
Cameron

>
> 2c
>
> On Fri, 2003-09-12 at 14:40, Cameron B. Prince wrote:
> > Hi all,
> >
> > I have a report creation perl script that takes about 15
> minutes to run and
> > I need to fork it. I tried the code from v1:
> >
> >   use strict;
> >   use POSIX 'setsid';
> >   use Apache::SubProcess;
> >
> >
> >   my  = shift;
> >   ->send_http_header("text/plain");
> >
> >   {CHLD} = 'IGNORE';
> >   defined (my  = fork) or die "Cannot fork: \n";
> >   if () {
> >     print "Parent 25481 has finished, kid's PID: \n";
> >   } else {
> >       ->cleanup_for_exec(); # untie the socket
> >       chdir '/'                or die "Can't chdir to /: ";
> >       open STDIN, '/dev/null'  or die "Can't read /dev/null: ";
> >       open STDOUT, '>/dev/null'
> >           or die "Can't write to /dev/null: ";
> >       open STDERR, '>/tmp/log' or die "Can't write to /tmp/log: ";
> >       setsid or die "Can't start a new session: ";
> >
> >       select STDERR;
> >       local $| = 1;
> >       warn "started\n";
> >       # do something time-consuming
> >       sleep 1, warn "sh\n" for 1..20;
> >       warn "completed\n";
> >
> >       CORE::exit(0); # terminate the process
> >   }
> >
> >
> > First problem, Apache::SubProcess doesn't seem to contain
> those methods
> > anymore.
> > Second problem is open.
> >
> > Can anyone tell me the proper way to fork with v2?
> >
> > Thanks,
> > Cameron
> --
> Richard F. Rebel
> [EMAIL PROTECTED]
> t. 212.239.0000
>

Reply via email to