#include #include #include #include #include #include #include #include int _daemon(int nochdir, int noclose){ pid_t pid; // pid_t defined in sys/types.h // pid_t is a signed int data type pid = fork(); // fork of the parent process // fork() function defined in unistd.h if (pid < 0){ exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h } else if (pid > 0){ exit(EXIT_FAILURE); } if (setsid() == -1){ return -1; } return 0; }