Run as a daemon or service: Difference between revisions

→‎{{libheader|BSD libc}}: doesn't really simplify much: there's freopen anyway
(→‎{{header|C}}: Describe BSDisms. Keep dup2() in program.)
(→‎{{libheader|BSD libc}}: doesn't really simplify much: there's freopen anyway)
Line 12:
[[BSD]] provides a convenient [http://netbsd.gw.com/cgi-bin/man-cgi?daemon+3+NetBSD-current daemon(3)] function. [[GNU]] libc also provides [http://www.kernel.org/doc/man-pages/online/pages/man3/daemon.3.html daemon(3)], but [[POSIX]] omits it, so it is not portable. Other BSDisms in this program are __progname and <err.h>.
 
The task also wants to redirect stdout. This program does so with [http://netbsd.gw.com/cgi-bin/man-cgi?dup2+2+NetBSD-current dup2(2)]. IfHad we omitwanted theto directly requirementwrite to redirecta stdout;file, we cancould simplifyopen the program by removing dup2(), by opening our file with <code>file = fopen(argv[1], "a")</code>, and by writingwrite to ''file'' instead of ''stdout''.
 
<lang c>#include <err.h>
Anonymous user