
On Jan 7, 2010, at 14:44 , Bas van Dijk wrote:
On Thu, Jan 7, 2010 at 5:18 PM, Bulat Ziganshin
wrote: Thursday, January 7, 2010, 6:25:34 PM, you wrote:
So now I'm confused... are these standard file handles always open on program startup or are there abnormal situations when they are closed?
afaik, parent process may close them before executing your program, it's used in particular for running daemons
Thanks Bulat for explaining.
POSIX actually discourages that, because it's so common for library routines to assume they can write error messages to stderr; the approved way to handle daemons is to open the standard file handles on /dev/null, *not* to close them. There are systems that violate this, however (the most "fun" one I've encountered is Applications menu commands in Mac OS X 10.4's X11.app; bash partially works around it, but not entirely). So the correct thing to do is to check if they are open on startup, and if not open /dev/null. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH