Browse Source

add daemonize code from other project. (Might be integrated in a future class but i am not sure right now

master
Georg Hopp 14 years ago
parent
commit
72e46b3a1e
  1. 23
      src/daemonize.c

23
src/daemonize.c

@ -0,0 +1,23 @@
#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);
}
Loading…
Cancel
Save