Return TypeFunction nameArguments
voidDemonize(void)

Declared in file: hzProcess.h
Defined in file : hzProcess.cpp

Function Logic:

0:START 1:bBeenHere 2:items 3: No text 4:bBeenHere fork pid 5:pid<0 6:getpid exit 7:pid>0 8:getpid exit 9:umask setsid sid 10:sid<0 11:getpid exit 12:close close close 13: No text

Function body:

void Demonize (void)
{
   static  bool    bBeenHere = false ;
   if (bBeenHere)
   {
       std::cerr << "Attempt to call Demonize more than once" << std::endl ;
       return ;
   }
   bBeenHere = true ;
   pid_t   pid ;
   pid_t   sid ;
   pid = fork();
   if (pid < 0)
   {
       std::cerr << "Parent [" << getpid() << "] begets crap PID [" << pid << "] - exiting" << std::endl ;
       exit(EXIT_FAILURE);
   }
   if (pid > 0)
   {
       std::cout << "Exiting parent [" << getpid() << "] starting [" << pid << "]" << std::endl ;
       exit(EXIT_SUCCESS);
   }
   umask(0);
   sid = setsid();
   if (sid < 0)
   {
       std::cout << "Parent [" << getpid() << "] begets bad SID of [" << sid << "]" << std::endl ;
       exit(EXIT_FAILURE);
   }
   close(STDIN_FILENO);
   close(STDOUT_FILENO);
   close(STDERR_FILENO);
}