Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Keeping grandchild alive when mod_perl process is killed

by etcshadow (Priest)
on Nov 20, 2004 at 22:36 UTC ( [id://409292]=note: print w/replies, xml ) Need Help??

in reply to Keeping grandchild alive when mod_perl process is killed

So, for the record, after applying Zaxo's help, this is what you get:
use Apache::SubProcess; my $pid = fork; if (defined $pid && !$pid) { Apache->request->cleanup_for_exec(); $pid = fork; if (defined $pid && !$pid) { close STDERR; close STDIN; close STDOUT; use POSIX(); POSIX::setsid(); ########## # do long running stuff here ########## CORE::exit; } else { CORE::exit; } } waitpid($pid, 0);
Although before anyone else plows into this, you should probably look up some info on daemonization to understand it. Also, you'll almost certainly want to reopen STDOUT and STDERR to some log files or something. In short, this is a very small piece of the whole puzzle, so please don't take that snippet of code out of context and think that you've got an entire solution to the problem of long-running processes spawned by a web server.

Oh, and if your fork fails (returns undef), you should really trap that and deal with it appropriately... I was just posting the miminal amount of code to express my question. I don't mean for this to be really exemplar code.

------------ :Wq Not an editor command: Wq

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://409292]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-07-12 21:29 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.