rsiedl has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I'm running a CGI script which forks into the background and continues processing while the main script returns a message to the browser.
I would like to know how I can see any errors which might occur in the forked part.
Normally the CGI gets printed to the apache error log but I'm not seeing anything in there comming from the fork (and I know it is having errors).
Can anyone help me out?

Cheers,
Reagen

Replies are listed 'Best First'.
Re: Errors from forked process
by aufflick (Deacon) on Apr 20, 2006 at 06:11 UTC
    Like jeshuaok I suspect that Apache post-cgi cleanup is closing your stdout/stderr file handles.

    While not the best final solution, the first thing I would try would be to open a logging file and alias it to STDERR. Something like this:

    open NEW_STDERR, ">/tmp/mylog.$$" or die "with some reasonable message +"; *STDERR = *NEW_STDERR;
Re: Errors from forked process
by blazar (Canon) on Apr 20, 2006 at 09:22 UTC
    I would like to know how I can see any errors which might occur in the forked part.

    Then just have it maintain its own log(s). Either roll a system yourself or use a module like Log::Log4perl.

Re: Errors from forked process
by Anonymous Monk on Apr 20, 2006 at 10:36 UTC
Re: Errors from forked process
by jesuashok (Curate) on Apr 20, 2006 at 05:28 UTC
    Hi

    Points to ponder on Fork and Apache.
    Apache logging pipe, the new child also inherits this connection, including any unprocessed data, and can pick up where the exited child left off.

    Apache runs cleanup code per-child after a fork and before executing cgi scripts. This was not handled properly, and R/Apache caused the child to segfault.

    "Keep pouring your ideas"