cxxtools::posix::Fork Class Reference

A simple wrapper for the system function fork(2). More...

#include <cxxtools/posix/fork.h>

Public Member Functions

 Fork (bool now=true)
 ~Fork ()
void fork ()
pid_t getPid () const
bool parent () const
bool child () const
void setNowait ()
int wait (int options=0)

Detailed Description

A simple wrapper for the system function fork(2).

The advantage of using this class instead of fork directly is, easyness, robustness and readability due to less code. The constructor executes fork(2) and does error checking. The destructor waits for the child process, which prevents the creation of zombie processes. The user may decide to deactivate it or waiting explicitely to receive the return status, but this has to be done explicitely, which helps robustness.

Example:

{
cxxtools::Fork process;
if (process.child())
{
// we are in the child process here.
exit(0); // normally the child either exits or execs an other
// process
}
}

Constructor & Destructor Documentation

cxxtools::posix::Fork::Fork ( bool  now = true)
inline
cxxtools::posix::Fork::~Fork ( )
inline

Member Function Documentation

bool cxxtools::posix::Fork::child ( ) const
inline
void cxxtools::posix::Fork::fork ( )
inline
pid_t cxxtools::posix::Fork::getPid ( ) const
inline
bool cxxtools::posix::Fork::parent ( ) const
inline
void cxxtools::posix::Fork::setNowait ( )
inline
int cxxtools::posix::Fork::wait ( int  options = 0)
inline

The documentation for this class was generated from the following file:
  • include/cxxtools/posix/fork.h