#include <signal.h> #include <sys/types/h> #include <sys/stats.h> #include <unistd.h> #include <fcntl.h> void InitDaemon() { pid_t pid = 0; if ((pid = fock()) != 0) { exit(0); } setsid(); signal(SIGINT, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGCHLD, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGHUP, SIG_IGN); if ((pid = fock()) != 0) { exit(0); } umask(0); }