http://www.perlmonks.org?node_id=714909


in reply to Problem w/ forking CGI script

In my experience, you also need to close STDERR in the child (at least with recent Apaches), not only STDOUT.

Try adding

... } elsif (defined $pid) { # child does close STDOUT; # so parent can go on close STDERR; # <--- THIS ...

(The open STDERR, ">&=1"; which you find in merlyn's code doesn't implicitly close file descriptor number 2 (stderr) under the hood ... as you can verify using strace. )

The fact that it (seemingly) works with Safari probably has to do with different browser buffering behavior, i.e. it presumably processes partial content differently (before the HTTP request has completed). But that's just a guess — at the moment I don't have a Safari to investigate this further.  (You could check whether the individual Apache children (CGI processes) actually do terminate as expected in this case...)