Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

dsDaemon Class Reference

It's easy method to create UNIX daemon using C++. More...

#include <dsDaemon.h>

Inheritance diagram for dsDaemon:

dsHttpDaemon MyDaemon SimpleHttpDaemon List of all members.

Public Methods

 dsDaemon (char *progname, int max_children=50, int flags=0)
 dsDaemon (char *progname, char *pid_path, int max_children=50, int flags=0)
virtual ~dsDaemon ()
virtual int init_globals ()
virtual pid_t fork_child ()
virtual int child_work ()
virtual void shutdown_child ()
virtual int reinit ()
void kill_running ()

Protected Methods

void processPidFile ()
void addChild (pid_t npid)
void removeChild (pid_t npid)
int waitForFreeSlot (pid_t pid)
 dsDaemon ()


void daemonize (dsDaemon *sd, int options=0)
void dsSafeSleep (int secs, int nsecs=0)
int DaemonFlags (char *str)
void SIGCHLD_hdl (int sig)
void SIGANY_hdl (int sig)
void SIGINT_hdl (int sig)

Detailed Description

Writing daemon process is the most often task under UNIX.
This C++ wrapper allow you to do it for 5 minits.
It hide all portability and system interaction problems from application.

make daemon flags as enum inside class

Constructor & Destructor Documentation

dsDaemon::dsDaemon   [protected]

Create unitialised daemon sceletion, use it to create derived classes only

dsDaemon::dsDaemon char *    progname,
int    max_children = 50,
int    flags = 0

Create a daemon sceletion

  • progname unique name of daemon. used to create PID file
  • max_children number of children allowed in the same time
  • flags flags controling daemon behaviour see above.

dsDaemon::dsDaemon char *    progname,
char *    pid_path,
int    max_children = 50,
int    flags = 0

dsDaemon::~dsDaemon   [virtual]

Member Function Documentation

void dsDaemon::addChild pid_t    npid [protected]

int dsDaemon::child_work   [virtual]

This function does per child actions

Reimplemented in dsHttpDaemon.

pid_t dsDaemon::fork_child   [virtual]

fork child. Default function increase child counter and then fork. It's better to call return dsDaemon::fork_child() at the end of overloaded function. if overloaded function returns -1 (fork error) child will not be intialised.

Reimplemented in dsHttpDaemon.

int dsDaemon::init_globals   [virtual]

Perform tasks after daemon detach, but before first fork all file handlers is closed to this point.

Reimplemented in dsHttpDaemon.

void dsDaemon::kill_running  

read pid file and kill running instance

void dsDaemon::processPidFile   [protected]

int dsDaemon::reinit   [virtual]

Function to call from SIGHUP handler. Week point use it with care.

void dsDaemon::removeChild pid_t    npid [protected]

void dsDaemon::shutdown_child   [virtual]

This function called when child terminated wether by SIGTERM or normally

Reimplemented in dsHttpDaemon.

int dsDaemon::waitForFreeSlot pid_t    pid [protected]

Waits for free slot in child array, and returns number of found slot

Friends And Related Function Documentation

int DaemonFlags char *    str [friend]

Convert text reperesentation of daemon file into binary flags

void daemonize dsDaemon *    sd,
int    options = 0

Perform basic system tasks to become a daemon: close all handlers, allocate new process group and detach

  • sd pointer to dsDaemon object
  • options daemon flags

void dsSafeSleep int    secs,
int    nsecs = 0

safe sleep: implement sleep by nanosleep or select timer (TODO), instead of using SIGALARM or sleep() to avoid possible interference with user application

void SIGANY_hdl int    sig [friend]

void SIGCHLD_hdl int    sig [friend]

void SIGINT_hdl int    sig [friend]

The documentation for this class was generated from the following files:
Generated on Mon May 16 18:26:59 2005 for libdms4 by doxygen1.3-rc2