Doxygen Source Code Documentation
        
Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search   
daemonize.c
Go to the documentation of this file.00001 #include <unistd.h>
00002 #include <stdio.h>
00003 
00004 
00005 
00006 
00007 
00008 void daemonize(void)
00009 {
00010    pid_t pid ;
00011 
00012    pid = fork() ;
00013    if( pid < 0 )  exit(1) ;   
00014    if( pid > 0 ) _exit(0) ;   
00015 
00016    setsid() ;
00017 
00018    pid = fork() ;
00019    if( pid < 0 )  exit(1) ;   
00020    if( pid > 0 ) _exit(0) ;   
00021 
00022    chdir("/") ;
00023    freopen("/dev/null","r",stdin)  ;
00024    freopen("/dev/null","w",stdout) ;
00025    freopen("/dev/null","w",stderr) ;
00026 }