perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Smith <>
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

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.

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

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:
    else {
        warn "starting child $$\n";
        $req_rec->cleanup_for_exec( ); # untie the
        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 [$$]

        # 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; -]
<xmp>[+ $output +]</xmp>

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message