libmoost
moost::process::daemon Class Reference

Provides everything necessary to convert a process into a daemon. More...

#include <daemon.hpp>

Collaboration diagram for moost::process::daemon:

List of all members.

Classes

struct  default_child_init_func

Public Member Functions

 daemon (bool exit_parent, boost::function0< bool > child_init_func)
 Forks a child process.
 daemon (bool exit_parent)
 Forks a child process.
 daemon (boost::function0< bool > child_init_func)
 Forks a child process.
pid_t get_pid () const
 Get the child process ID.
bool is_child () const
 Is this process the child?
bool is_parent () const
 Is this process the parent.

Static Public Member Functions

static void sleep_forever ()
 Once called, never returns - puts this thread to sleep forever.

Private Member Functions

void init (bool exit_parent, boost::function0< bool > child_init_func)

Private Attributes

daemon_impl daemon_impl_

Detailed Description

Provides everything necessary to convert a process into a daemon.

You can use this class to fork your process as a daemon. It encapsulates everything that will be required for the OS being targetted via a nice and simple to use interface.

Definition at line 46 of file daemon.hpp.


Constructor & Destructor Documentation

moost::process::daemon::daemon ( bool  exit_parent,
boost::function0< bool >  child_init_func 
) [inline]

Forks a child process.

Forks a child process and takes care of everything necessary to make it a daemon. Allows caller to prevent termination of parent and to perform child initialisation.

Parameters:
[in]exit_parentIf 'true' the parent will exit without returning
[in]child_init_funcCalled after spawning the child but before performing daemonisation stuff to turn child into a real daemon. Should return a bool, with true indicating all daemonising tasks have been completed or are not necessary so the daemon class will not do these additional daemonising steps.
Exceptions:
Ifthere is an error during the forking a standard runtime_error exception will be thrown.

Definition at line 70 of file daemon.hpp.

Here is the call graph for this function:

moost::process::daemon::daemon ( bool  exit_parent) [inline]

Forks a child process.

Forks a child process and takes care of everything necessary to make it a daemon. Allows caller to prevent termination of parent.

Parameters:
[in]exit_parentIf 'true' the parent will exit without returning
Exceptions:
Ifthere is an error during the forking a standard runtime_error exception will be thrown.

Definition at line 85 of file daemon.hpp.

Here is the call graph for this function:

moost::process::daemon::daemon ( boost::function0< bool >  child_init_func) [inline]

Forks a child process.

Forks a child process and takes care of everything necessary to make it a daemon. Allows caller to perform child initialisation.

Parameters:
[in]child_init_funcCalled after spawning the child but before performing daemonisation stuff to turn child into a real daemon. Should return a bool, with true indicating all daemonising tasks have been completed or are not necessary so the daemon class will not do these additional daemonising steps.
Exceptions:
Ifthere is an error during the forking a standard runtime_error exception will be thrown.

Definition at line 104 of file daemon.hpp.

Here is the call graph for this function:


Member Function Documentation

pid_t moost::process::daemon::get_pid ( ) const [inline]

Get the child process ID.

Returns:
If we're the parent we get the childs pid, if we're the child we get zero.

Definition at line 115 of file daemon.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void moost::process::daemon::init ( bool  exit_parent,
boost::function0< bool >  child_init_func 
) [inline, private]

Definition at line 153 of file daemon.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool moost::process::daemon::is_child ( ) const [inline]

Is this process the child?

Returns:
If child return true else return false

Definition at line 123 of file daemon.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool moost::process::daemon::is_parent ( ) const [inline]

Is this process the parent.

Returns:
If child return false else return true

Definition at line 131 of file daemon.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static void moost::process::daemon::sleep_forever ( ) [inline, static]

Once called, never returns - puts this thread to sleep forever.

A help function that can be called from the 'main' thread of a process to put it to sleep forever so that the "worker" threads can do their thing. Once this is called the only way to terminate the process is to register a quit handler to stop the worker threads and then explicitly call exit().

Definition at line 141 of file daemon.hpp.


Member Data Documentation

Definition at line 164 of file daemon.hpp.


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