server 0.0.1
basicserverinfrastructure

src/daemonize.c

Go to the documentation of this file.
00001 #include <stdio.h>      /* for printf() and fprintf() */
00002 #include <unistd.h>     /* for getopt */
00003 #include <stdlib.h>
00004 
00005 
00006 void daemonize(void) {
00007     pid_t pid;
00008 
00009     if (0 > ((pid = fork()))) {
00010         perror("deamoinze[fork]");
00011         exit(EXIT_FAILURE);
00012     } else if (0 != pid) {
00013         exit(EXIT_SUCCESS);
00014     }
00015 
00016     /* make new child session leader */
00017     setsid();
00018 
00019     /* connect all standard streams to /dev/null */
00020     stderr = freopen("/dev/null", "w", stderr);
00021     stdin  = freopen("/dev/null", "r", stdin);
00022     stdout = freopen("/dev/null", "w", stdout);
00023 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines