process-cpp: core::posix::ChildProcess::DeathObserver Class Reference

process-cpp 3.0.0 A simple convenience library for handling processes in C++11.

Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
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
DeathObserver & | operator= (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< DeathObserver > | create_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

## ◆ DeathObserver() [1/2]

core::posix::ChildProcess::DeathObserver::DeathObserver | ( | const DeathObserver & |  | ) |
| delete

## ◆ ~DeathObserver()

virtual core::posix::ChildProcess::DeathObserver::~DeathObserver | ( |  | ) |
| virtualdefault

## ◆ DeathObserver() [2/2]

core::posix::ChildProcess::DeathObserver::DeathObserver | ( |  | ) |
| protecteddefault

## Member Function Documentation

## ◆ add()

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

  child | The child to be observed.

Returns
  true iff the child has been added to the list of observed child processes.

## ◆ child_died()

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.

## ◆ create_once_with_signal_trap()

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_error | if the given SignalTrap instance does not trap Signal::sig_chld.
  std::runtime_error | if there already is an instance of the death observer.

Definition at line 152 of file child_process.cpp.

Referenced by TESTP().

## ◆ has()

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

has checks whether the specified child is observed.

Parameters

  child | The child to check for.

Returns
  true iff the specified child is observed for state changes.

## ◆ on_sig_child()

virtual void core::posix::ChildProcess::DeathObserver::on_sig_child | ( |  | ) |
| pure virtual

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

## ◆ operator=()

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

## ◆ operator==()

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

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

- /build/process-cpp/src/process-cpp-3.0.1/include/core/posix/child_process.h
- /build/process-cpp/src/process-cpp-3.0.1/src/core/posix/child_process.cpp