1. Establishing new streams for file descriptors stdin, stdout, stderr
I'm trying to "daemonize" a server program which runs on a few different
Unix platforms according to Section 1.7 of the comp.unix.programmer FAQ,
but I'm tripping over a couple of details which I don't understand.
I've accomplished the first six steps. (up to closing file descriptors
0, 1, and 2 in order to release stdin, stdout, and stderr).
I'm not quite sure how to go about step 7:
7. Establish new open descriptors for stdin, stdout and stderr. Even if
you don't plan to use them, it is still a good idea to have them open.
The precise handling of these is a matter of taste; if you have a
logfile, for example, you might wish to open it as stdout or stderr,
and open `/dev/null' as stdin; alternatively, you could open
`/dev/console' as stderr and/or stdout, and `/dev/null' as stdin, or
any other combination that makes sense for your particular daemon.
I want to redirect stdout and stderr to append file which I know exists, and
redirect stdin to /dev/null
I'm ignorant of how to force this association. I know that I could use open()
to open the file, but then I would just get whatever file descriptor the
system decided to give me. Does open() always use the file descriptors
in ascending order? Such that if I close these three, then do three opens,
I will get first 0, then 1, then 2? If not, is there a semi-portable way to
force an open with a particular file descriptor?
Am I far off here?
Thanks in advance!
Get my e-mail address at www.nvmedia.com/jbeal
(Tired of the damn spam)
2. File locking as a mutual exclusion mechanism
3. file descriptor passing via streams ioctl (AIX 4.3)
4. print quota in solaris
5. passing file descriptors through stream pipes?
6. CGI-File not found
7. buffer flushing; converting file descriptor to stream pointer
8. bernoulli boxes as backup?
9. passing file descriptors through stream pipes?
10. C++ Streams and File Descriptors
11. file descriptors with C++ streams
12. file descriptor passing via streams ioctl (AIX 4.3)
13. interfacing a stream to a file descriptor