libmoost
|
Provides everything necessary to convert a process into a daemon. More...
#include <daemon.hpp>
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_ |
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.
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.
[in] | exit_parent | If 'true' the parent will exit without returning |
[in] | child_init_func | Called 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. |
If | there is an error during the forking a standard runtime_error exception will be thrown. |
Definition at line 70 of file daemon.hpp.
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.
[in] | exit_parent | If 'true' the parent will exit without returning |
If | there is an error during the forking a standard runtime_error exception will be thrown. |
Definition at line 85 of file daemon.hpp.
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.
[in] | child_init_func | Called 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. |
If | there is an error during the forking a standard runtime_error exception will be thrown. |
Definition at line 104 of file daemon.hpp.
pid_t moost::process::daemon::get_pid | ( | ) | const [inline] |
Get the child process ID.
Definition at line 115 of file daemon.hpp.
void moost::process::daemon::init | ( | bool | exit_parent, |
boost::function0< bool > | child_init_func | ||
) | [inline, private] |
Definition at line 153 of file daemon.hpp.
bool moost::process::daemon::is_child | ( | ) | const [inline] |
Is this process the child?
Definition at line 123 of file daemon.hpp.
bool moost::process::daemon::is_parent | ( | ) | const [inline] |
Is this process the parent.
Definition at line 131 of file daemon.hpp.
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.
Definition at line 164 of file daemon.hpp.