Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-16 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found