Our Daemonize() Function static void daemonize() { int i; pid_t pid; /* fork for the first time. */ if ((pid = fork()) != 0){ if (pid == -1){ warn("failed to fork into background! error '%s'", strerror(errno)); warn("reamining in foreground"); return; } /* parent, exit */ exit(0); } setsid(); /* ignore SIGHUP signals */ signal(SIGHUP, SIG_IGN); /* fork again */ if ((pid = fork()) != 0){ if (pid == -1){ warn("failed to fork into background! error '%s'", strerror(errno)); warn("remaining in foreground"); return; } /* parent, exit */ exit(0); }