Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

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    Become a daemon: fork, die, setsid, fork, die, disconnect 
00006 ------------------------------------------------------------------------------*/
00007 
00008 void daemonize(void)
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 }
 

Powered by Plone

This site conforms to the following standards: