You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
541 B
23 lines
541 B
#include <stdio.h> /* for printf() and fprintf() */
|
|
#include <unistd.h> /* for getopt */
|
|
#include <stdlib.h>
|
|
|
|
|
|
void daemonize(void) {
|
|
pid_t pid;
|
|
|
|
if (0 > ((pid = fork()))) {
|
|
perror("deamoinze[fork]");
|
|
exit(EXIT_FAILURE);
|
|
} else if (0 != pid) {
|
|
exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
/* make new child session leader */
|
|
setsid();
|
|
|
|
/* connect all standard streams to /dev/null */
|
|
freopen("/dev/null", "w", stderr);
|
|
freopen("/dev/null", "r", stdin);
|
|
freopen("/dev/null", "w", stdout);
|
|
}
|