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

Reply via email to