Re: exec and detach a subprocess

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

From: Stas Bekman
Subject: Re: exec and detach a subprocess
Date: 01:06 on 19 Feb 2005
Igor Shevchenko wrote:
> Hi all,
> 
> How can I launch a subprocess and have it completely detached from the 
> mod_perl2/apache2 environment ? All file descriptors closed, not in a process 
> group, etc.
> 
> I was trying to do it like this:
> 
> sub safe_exec {
>     return if fork() > 0;
>     
>     # close all descriptors
>     foreach my $fd ( 0, 3..1023 ) { close $fd }
>     
>     exec ( @_ );
>     CORE::exit;
> }
> 
> Unfortunately this doesn't close sockets which are listening on ports 80 and 
> 443. Tried it like this:
> 
> * start apache
> * run bg process from web page / script
> * stop apache
> * "ps auxww|grep httpd" doesn't show any httpd process running,
> "netstat -lp|grep http" shows ports 80 and 443, listening in a perl process 
> (my background script)
> 
> Because of this, apache fails to restart when any of background processes are 
> running. How do I close all file descriptors and sockets ?
> 
> (this is linux 2.6)


Igor, the techniques explained here don't work?
http://perl.apache.org/docs/1.0/guide/performance.html#Forking_and_Executing_Subprocesses_from_mod_perl

What about?
$r->spawn_proc_prog
http://perl.apache.org/docs/2.0/api/Apache/SubProcess.html#C_spawn_proc_prog_

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(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