Make program operate as a demon. Assumes UNIX type OS. Call very early on the the program. Has built in code to prevent multiple execution Arguments: None Returns: None

Return TypeFunction nameArguments
voidDemonize(void)

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

Function Logic:

0:START 1:unknown 2:items 3: No text 4:bBeenHere pid 5:unknown 6:items items 7:unknown 8:items items 9:items sid 10:unknown 11:items items 12:items items items 13: No text

Function body:

void Demonize (void)
{
   //  Category: Process
   //  
   //  Make program operate as a demon.
   //  Assumes UNIX type OS. Call very early on the the program. Has built in code to prevent multiple execution
   //  
   //  Arguments: None
   //  Returns: None
   static  bool    bBeenHere = false ; //  Already called marker
   if (bBeenHere)
   {
       std::cerr << "Attempt to call Demonize more than once" << std::endl ;
       return ;
   }
   bBeenHere = true ;
   pid_t   pid ;   //  Our process ID
   pid_t   sid ;   //  Our session ID
   //  Fork off the parent process
   pid = fork();
   if (pid < 0)
   {
       std::cerr << "Parent [" << getpid() << "] begets crap PID [" << pid << "] - exiting" << std::endl ;
       exit(EXIT_FAILURE);
   }
   //  If we got a good PID, then we can exit the parent process.
   if (pid > 0)
   {
       std::cout << "Exiting parent [" << getpid() << "] starting [" << pid << "]" << std::endl ;
       exit(EXIT_SUCCESS);
   }
   //  Change the file mode mask
   umask(0);
   //  Create a new SID for the child process
   sid = setsid();
   if (sid < 0)
   {
       std::cout << "Parent [" << getpid() << "] begets bad SID of [" << sid << "]" << std::endl ;
       exit(EXIT_FAILURE);
   }
   //  Close out the standard file descriptors
   close(STDIN_FILENO);
   close(STDOUT_FILENO);
   close(STDERR_FILENO);
}