Re: exec and detach a subprocess

[prev] [thread] [next] [Date index for 2005/02/21]

From: Igor
Subject: Re: exec and detach a subprocess
Date: 08:28 on 21 Feb 2005
Message-ID: 873053

On Monday 21 February 2005 10:20, You wrote:
---- Original Message ----------------------
Subject: Re: exec and detach a subprocess
From: Stas Bekman <stas@xxxxxx.xxx>
To: Igor Shevchenko <igor_mp@xxxxxxx.xxx.xx>
CC: modperl@xxxx.xxxxxx.xxx
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: $@\n";

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

(message missing)

exec and detach a subprocess
Igor Shevchenko 23:25 on 18 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 01:06 on 19 Feb 2005

Re: exec and detach a subprocess
Igor Shevchenko 14:29 on 19 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 16:44 on 19 Feb 2005

Re: exec and detach a subprocess
Igor Shevchenko 17:02 on 19 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 17:06 on 19 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 16:51 on 19 Feb 2005

Re: exec and detach a subprocess
Igor Shevchenko 17:18 on 19 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 17:26 on 19 Feb 2005

Re: exec and detach a subprocess
Igor Shevchenko 14:20 on 20 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 01:16 on 21 Feb 2005

Re: exec and detach a subprocess
Igor 08:28 on 21 Feb 2005

Re: exec and detach a subprocess
Stas Bekman 01:58 on 22 Feb 2005

Generated at 22:43 on 24 Feb 2005 by mariachi v0.52