perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Smith <matthew...@yahoo.com>
Subject use of STDERR in forked children
Date Wed, 28 Jun 2006 16:16:10 GMT
Hi,  I'm working on a mechanism to fork a a long
running child process.  I've followed the standard
mod_perl forking wisdom in
http://modperlbook.org/html/ch10_02.html.

My issue is that warn() doesn't work in the child
process, though printing directly to STDERR does.

Also, I want STDERR to go to the apache log like it
normally would, but I don't know how to determine what
the path to the log is. I can't hard code it since it
changes depending on the environment (dev vs. qa vs.
prod).

I haven't tried this using Apache::Registry (since we
don't run it) but I thought it might be and Embperl
thing since I couldn't find anything on the mod_perl
lists...

I'm using Apache 1.3 and Embperl 1.36

Your help is greatly appreciated.

Here's the code:
[# SNIP #]
[!
    use POSIX 'setsid';
    use Apache;
!]
[-
    my $childPid = undef;
    $SIG{CHLD} = 'IGNORE';

    if ($childPid = fork) {
        $output =  "Parent $$ has finished, kid's PID:
$childPid\n";
    }
    else {
        warn "starting child $$\n";
        $req_rec->cleanup_for_exec( ); # untie the
socket
        chdir '/'                 or die "Can't chdir
to /: $!";
        open STDIN, '/dev/null'   or die "Can't read
/dev/null: $!";
        open STDOUT, '>/dev/null' or die "Can't write
to /dev/null: $!";
        open STDERR, '>>/tmp/log'  or die "Can't write
to /tmp/log: $!";
        setsid                    or die "Can't start
a new session: $!";

        my $oldfh = select STDERR;
        local $| = 1;
        select $oldfh;

        # ends up in /tmp/log
        print STDERR "Where do the children [$$]
play?\n";

        # ends up nowhere
        warn "Where do the children [$$] play?\n";

        # do something time-consuming
        for (1..20) {
            sleep 1;
            warn "$_\n";
        }
        warn "completed $$\n";

        CORE::exit(0); # terminate the process
    }
-]
[-  $dbgLogLink = 0; -]
<html><head><body>
<xmp>[+ $output +]</xmp>
</body></html>
[# ENDSNIP #]

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message