Difference between revisions of "Daemonise.c"
From Organic Design wiki
m |
m |
||
| Line 4: | Line 4: | ||
if ((pid = fork()) < 0) { | if ((pid = fork()) < 0) { | ||
| − | + | logAdd("fork()"); | |
//shutdown(evListen->h, 2); ??? | //shutdown(evListen->h, 2); ??? | ||
| − | return errno; | + | //return errno; |
} else if (pid) return 0; | } else if (pid) return 0; | ||
Revision as of 04:10, 21 July 2006
// Convert running program into a system daemon pid_t pid; int hNull;
if ((pid = fork()) < 0) { logAdd("fork()"); //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();



