Message-ID: 873053

On Monday 21 February 2005 10:20, You wrote:
---- Original Message ----------------------
Subject: Re: exec and detach a subprocess
From: Stas Bekman <[EMAIL PROTECTED]>
To: Igor Shevchenko <[EMAIL PROTECTED]>
CC: modperl@perl.apache.org
Date: 21 Feb 2005 10:17:49
--------------------------------------------

> Igor Shevchenko wrote:
> > A small followup to this case.
> > 
> > Looks like mp2 or apache2 are killing background process, by PID; Probably 
> > in 
> > a cleanup handler for the request. I had to add additional "return if 
> > fork() 
> >>0;" to the exec_helper.pl script to make bg processes survice.
> 
> what do you mean by background proc?
> 
> so you do an additional fork? where do you return() to? it's probably 
> exit(), no? show us the whole code snippet?

Here's it:

#!/usr/bin/perl -w
use strict;
use warnings;
use POSIX ();

chdir '/safe/dir';

close STDIN;
open STDOUT, '+>>', '/path/to/apache/error_log';
open STDERR, '>&STDOUT';

exit if fork() > 0; # fork once again

POSIX::setsid;

exec ( @ARGV ) or die "Failed to exec subprocess: [EMAIL PROTECTED]";

1;


Without the additional fork in "exit if fork() > 0;", background scripts which 
are started from exec(...) are killed when request is complete. Without the 
additional fork(), the PID for the bg process will be the same as for the 
"exec_helper.pl" script (since "exec" is used). Apache (apr?) knows this PID 
and it looks like it sends it a SIGKILL signal at request cleanup phase. I was 
not able trap other signals.

--
Best Regards,
Igor Shevchenko

Reply via email to