分类: C/C++
2007-11-19 19:00:49
void GoDaemon(void) { pid_t fs; printf("Initializing daemon mode\n"); if(getppid() != 1) { fs = fork(); if(fs > 0) exit(0); /* parent */ if(fs < 0) { perror("fork"); exit(1); } setsid(); } chdir("/");/* redirect stdin/stdout/stderr to /dev/null */ close(0); close(1); close(2); #ifdef DEBUG open("/tmp/snort.debug", O_CREAT | O_RDWR); #else open("/dev/null", O_RDWR); #endif dup(0); dup(0); return; } |