cxxtools::posix Namespace Reference

Classes

class  CommandInput
 cxxtools::posix::CommandInput starts a process and the stdin is connected to the current process. More...
class  CommandOutput
 cxxtools::posix::CommandOutput starts a process and the stdout of the process can be read. More...
class  Exec
 cxxtools::posix::Exec is a wrapper around the exec?? functions of posix. More...
class  Fork
 A simple wrapper for the system function fork(2). More...
class  Pipe
class  Pipestreambuf
 Simple unix pipe iostream. More...
class  Pipestream

Functions

void daemonize (const std::string &pidfile=std::string())
 This function makes a background daemon process out of the current process.

Function Documentation

void cxxtools::posix::daemonize ( const std::string &  pidfile = std::string())

This function makes a background daemon process out of the current process.

The current process is forked twice and the 2 parents are exited, so that only the single child is kept. The standard input, standard output and standard error output are redirected to /dev/null. When a pidfile is passed, the pid of the child is written to that file and a signal handler is installed, which removes the file, when the process is terminated unsing SIGTERM.