exec and detach a subprocess

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

From: Igor Shevchenko
Subject: exec and detach a subprocess
Date: 23:25 on 18 Feb 2005
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)

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