#include /* for printf() and fprintf() */ #include /* for getopt */ #include void daemonize(void) { pid_t pid; if (0 > ((pid = fork()))) { perror("deamoinze[fork]"); exit(EXIT_FAILURE); } else if (0 != pid) { exit(EXIT_SUCCESS); } /* make new child session leader */ setsid(); /* connect all standard streams to /dev/null */ freopen("/dev/null", "w", stderr); freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); }