Doxygen Source Code Documentation
daemonize.c File Reference
#include <unistd.h>#include <stdio.h>Go to the source code of this file.
Functions | |
| void | daemonize (void) |
Function Documentation
|
|
Definition at line 8 of file daemonize.c.
00009 {
00010 pid_t pid ;
00011
00012 pid = fork() ;
00013 if( pid < 0 ) exit(1) ; /* fork failed */
00014 if( pid > 0 ) _exit(0) ; /* parent exits */
00015
00016 setsid() ;
00017
00018 pid = fork() ;
00019 if( pid < 0 ) exit(1) ; /* fork failed */
00020 if( pid > 0 ) _exit(0) ; /* parent exits */
00021
00022 chdir("/") ;
00023 freopen("/dev/null","r",stdin) ;
00024 freopen("/dev/null","w",stdout) ;
00025 freopen("/dev/null","w",stderr) ;
00026 }
|