process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
core::posix::ChildProcess::DeathObserver Class Referenceabstract

The DeathObserver class observes child process' states and emits a signal when a monitored child has died. More...

#include <child_process.h>

+ Collaboration diagram for core::posix::ChildProcess::DeathObserver:

Public Member Functions

 DeathObserver (const DeathObserver &)=delete
 
virtual ~DeathObserver ()=default
 
DeathObserveroperator= (const DeathObserver &)=delete
 
bool operator== (const DeathObserver &) const =delete
 
virtual bool add (const ChildProcess &child)=0
 add adds the specified child to the list of observed child processes. More...
 
virtual bool has (const ChildProcess &child) const =0
 has checks whether the specified child is observed. More...
 
virtual const core::Signal< ChildProcess > & child_died () const =0
 child_died is emitted whenever an observed child ceases to exist. More...
 
virtual void on_sig_child ()=0
 Checks and reaps all child processes registered with the observer instance. More...
 

Static Public Member Functions

static std::unique_ptr< DeathObservercreate_once_with_signal_trap (std::shared_ptr< SignalTrap > trap)
 Creates the unique instance of class DeathObserver. More...
 

Protected Member Functions

 DeathObserver ()=default
 

Detailed Description

The DeathObserver class observes child process' states and emits a signal when a monitored child has died.

Please note that the name of this class is morbid for a reason: Listening for SIGCHLD is not enough to catch all dying children. Whenever a SIGCHLD is received, we have to wait for all the children of this process and reap all monitored ones. We are thus changing state and potentially race with other wait operations on children.

Definition at line 56 of file child_process.h.

Constructor & Destructor Documentation

core::posix::ChildProcess::DeathObserver::DeathObserver ( const DeathObserver )
delete
virtual core::posix::ChildProcess::DeathObserver::~DeathObserver ( )
virtualdefault
core::posix::ChildProcess::DeathObserver::DeathObserver ( )
protecteddefault

Member Function Documentation

virtual bool core::posix::ChildProcess::DeathObserver::add ( const ChildProcess child)
pure virtual

add adds the specified child to the list of observed child processes.

Parameters
childThe child to be observed.
Returns
true iff the child has been added to the list of observed child processes.
virtual const core::Signal<ChildProcess>& core::posix::ChildProcess::DeathObserver::child_died ( ) const
pure virtual

child_died is emitted whenever an observed child ceases to exist.

std::unique_ptr< core::posix::ChildProcess::DeathObserver > core::posix::ChildProcess::DeathObserver::create_once_with_signal_trap ( std::shared_ptr< SignalTrap trap)
static

Creates the unique instance of class DeathObserver.

Exceptions
std::logic_errorif the given SignalTrap instance does not trap Signal::sig_chld.
std::runtime_errorif there already is an instance of the death observer.

Definition at line 152 of file child_process.cpp.

virtual bool core::posix::ChildProcess::DeathObserver::has ( const ChildProcess child) const
pure virtual

has checks whether the specified child is observed.

Parameters
childThe child to check for.
Returns
true iff the specified child is observed for state changes.
virtual void core::posix::ChildProcess::DeathObserver::on_sig_child ( )
pure virtual

Checks and reaps all child processes registered with the observer instance.

DeathObserver& core::posix::ChildProcess::DeathObserver::operator= ( const DeathObserver )
delete
bool core::posix::ChildProcess::DeathObserver::operator== ( const DeathObserver ) const
delete

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