Not only stdin, stdout and stderr should be closed, but all open files.
From "Advanced UNIX Programming," W. Richard Stevens, Addison-Weseley, 18th Printing, 1999, p. 417.
Urgent file descriptors must be closed. This prevents the daemon from accessing any descriptors that it may have inherited from its parent (which may be a shell or some other process).
Mr. Stevens' suggestion is to get the maximum file descriptor and close all files to this value.
The cited chapter is devoted to "The processes of the demon." Note that closing file descriptors is only one in five points when writing daemons.
source share