You can google for "closing stdout apache" for a bunch of discussion on how to do it, But basically the code is
$| = 1; # need either this or to explicitly flush stdout, etc.
# before forking
print "Content-type: text/plain\n\n";
print "Going to start the fork now\n";
if ( !defined(my $pid = fork())) {
print STDERR "fork error\n";
exit(1);
} elsif ($pid == 0) {
# child
close(STDOUT);close(STDIN);close(STDERR);
exec('./fork-long-process-test-process'); # lengthy processing
} else {
# parent
print "forked child \$pid= $pid\n";
exit 0;
}
When I saw the node title, the first thing that poped up in my mind was a "big red warning flag" not to use exec in threads. Why? Because the exec will take over the process completely and destroy all other threads that were running under the parent, including the parent. You can "fork-and-exec" from a thread with no problem. The way you are describing your code, I don't see why you are even using threads to begin with? But you are seemingly on windows, and I'm clueless on how Windows does things. I mention it, because it may cause some sort of "weird" problem where you can't close STDOUT because the parent was destroyed.
I'm not really a human, but I play one on earth.
flash japh
|