Daemonise.c
From Organic Design wiki
pid_t pid; int hNull;
if ((pid = fork()) < 0) { syslog(LOG_ERR, "fork: %m"); shutdown(evListen->h, 2); return errno; } else if (pid) return 0;
close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO);
hNull = open("/dev/null", O_RDWR); dup2(hNull, STDIN_FILENO); dup2(hNull, STDOUT_FILENO); dup2(hNull, STDERR_FILENO);
if(hNull > STDERR_FILENO) close(hNull);
setsid();



