fng has asked for the wisdom of the Perl Monks concerning the following question:
Later on, my daemon wants to fork itself to do some background work, and have the worker process notify the parent via a "Safe Pipe Open" , so I have something like:fork ...etc close(STDOUT); ...etc setsid();
but i never see the output in the parent b/c the child inherits a closed STDOUT. What is the right way to both close STDOUT for the parent's daemonization sake, but still use the nice open($fh,"-|") to allow the code to talk?$kidpid=open($fh,"-|"); #err handling omitted if ($kidpid) { while(<$fh>) {print;} close($fh); # implicit waitpid } else { print "hello parent\n"; exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: right way to reopen STDOUT in a child
by almut (Canon) on May 24, 2007 at 00:43 UTC |