Static Public Member Functions | List of all members
G::Daemon Class Reference

A class for deamonising the calling process. More...

#include <gdaemon.h>

Static Public Member Functions

static void detach ()
 Detaches from the parent environment. More...
 
static void detach (PidFile &pid_file)
 An overload which allows for a delayed write of the new process-id to a file. More...
 

Detailed Description

A class for deamonising the calling process.

Deamonisation includes fork()ing, detaching from the controlling terminal, setting the process umask, etc. The windows implementation does nothing.

See also
G::Process

Definition at line 44 of file gdaemon.h.

Member Function Documentation

void G::Daemon::detach ( )
static

Detaches from the parent environment.

This typically involves fork()ing, _exit()ing the parent, and calling setsid() in the child.

Definition at line 32 of file gdaemon_unix.cpp.

References G::Process::cd(), G::NewProcess::fork(), and G::NewProcess::Parent.

Referenced by detach().

void G::Daemon::detach ( PidFile pid_file)
static

An overload which allows for a delayed write of the new process-id to a file.

A delayed write is useful for network daemons which open a listening port. A second instance of the process will fail on startup, and should not overwrite the pid file of the running server. In this situation PidFile::commit() should be called just before entering the event loop.

Throws PidFile::Error on error.

Definition at line 26 of file gdaemon_unix.cpp.

References G::PidFile::check(), and detach().


The documentation for this class was generated from the following files: