Server 0.0.1
HTTP/REST server implementation

src/utils/daemonize.c

Go to the documentation of this file.
00001 
00025 #include <stdio.h>      // for printf() and fprintf()
00026 #include <unistd.h>     // for getopt
00027 #include <stdlib.h>
00028 
00029 
00030 void daemonize(void) {
00031     pid_t pid;
00032 
00033     if (0 > ((pid = fork()))) {
00034         perror("deamoinze[fork]");
00035         exit(EXIT_FAILURE);
00036     } else if (0 != pid) {
00037         exit(EXIT_SUCCESS);
00038     }
00039 
00040     // make new child session leader
00041     setsid();
00042 
00043     // connect all standard streams to /dev/null
00044     stderr = freopen("/dev/null", "w", stderr);
00045     stdin  = freopen("/dev/null", "r", stdin);
00046     stdout = freopen("/dev/null", "w", stdout);
00047 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines