Why is it necessary to close standard input/output/error when writing a (unix) daemon?
Why is it necessary to close standard input/output/error when writing a (unix) daemon?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t have to definitely close standard output/error, but you have to be sure where your daemon (and child) are going to writing to. Redirecting the output to a log file is a common practice.
Closing standard input is required so that the daemon (and/or child) doesn’t get stuck trying to read some input from the user.
But if you’re going to detach you daemon from a controlling TTY using
setsid(), the standard input/output/error are going to be invalid.