core::posix::ChildProcess Class Reference

The Process class models a child process of this process. More...

`#include <child_process.h>`

Inheritance diagram for core::posix::ChildProcess:
Collaboration diagram for core::posix::ChildProcess:

## Classes

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

## Public Member Functions

| ~ChildProcess ()
wait::Result | wait_for (const wait::Flags &flags)
| Wait for the child process to change state.
std::istream & | cerr ()
| Access this process's stderr.
std::ostream & | cin ()
| Access this process's stdin.
std::istream & | cout ()
| Access this process's stdout.
Public Member Functions inherited from core::posix::Process
| Process (pid_t pid)
| Creates a process instance wrapping an existing process.
virtual | ~Process () noexcept
| Frees resources associated with the process.
virtual pid_t | pid () const
| Query the pid of the process.
virtual ProcessGroup | process_group_or_throw () const
| Queries the id of the process group this process belongs to.
virtual ProcessGroup | process_group (std::error_code &se) const noexcept(true)
| Queries the id of the process group this process belongs to.
Public Member Functions inherited from core::posix::Signalable
virtual void | send_signal_or_throw (Signal signal)
| Sends a signal to this signalable object.
virtual void | send_signal (Signal signal, std::error_code &e) noexcept(true)
| Sends a signal to this signalable object.

## Static Public Member Functions

static ChildProcess | invalid ()
| Creates an invalid ChildProcess.
Static Public Member Functions inherited from core::posix::Process
static Process | invalid ()
| Returns an invalid instance for testing purposes.

## Friends

ChildProcess | fork (const std::function< posix::exit::Status()> &main, const StandardStream &flags)
| fork forks a new process and executes the provided main function in the newly forked process.
ChildProcess | vfork (const std::function< posix::exit::Status()> &main, const StandardStream &flags)
| fork vforks a new process and executes the provided main function in the newly forked process.

## Additional Inherited Members

Protected Member Functions inherited from core::posix::Signalable
CORE_POSIX_DLL_LOCAL | Signalable (pid_t pid)

## Detailed Description

The Process class models a child process of this process.

In addition to the functionality offered by the Process class, an instance of ChildProcess offers functionality to wait for status changes of the child process and to access the child process's standard streams if they have been redirected when forking or exec'ing.

Definition at line 43 of file child_process.h.

## Constructor & Destructor Documentation

## ~ChildProcess()

core::posix::ChildProcess::~ChildProcess | ( |  | ) |

Definition at line 341 of file child_process.cpp.

## Member Function Documentation

## cerr()

std::istream & core::posix::ChildProcess::cerr | ( |  | ) |

Access this process's stderr.

Definition at line 382 of file child_process.cpp.

Referenced by TEST().

## cin()

std::ostream & core::posix::ChildProcess::cin | ( |  | ) |

Access this process's stdin.

Definition at line 387 of file child_process.cpp.

Referenced by TEST(), and TEST().

## cout()

std::istream & core::posix::ChildProcess::cout | ( |  | ) |

Access this process's stdout.

Definition at line 392 of file child_process.cpp.

Referenced by TEST(), TEST(), and TEST().

## invalid()

ChildProcess core::posix::ChildProcess::invalid | ( |  | ) |

static

Creates an invalid ChildProcess.

Returns
  An invalid ChildProcess instance.

Definition at line 325 of file child_process.cpp.

## wait_for()

wait::Result core::posix::ChildProcess::wait_for | ( | const wait::Flags & | flags | ) |

Wait for the child process to change state.

Parameters

  [in] | flags | Alters the behavior of the wait operation.

Returns
  Result of the wait operation, as well as information about the reasons for a child process's state change.

Definition at line 345 of file child_process.cpp.

References core::posix::wait::Result::continued, core::posix::wait::Result::core_dumped, core::posix::wait::Result::detail, core::posix::wait::Result::exited, core::posix::wait::Result::if_exited, core::posix::wait::Result::if_signaled, core::posix::wait::Result::if_stopped, core::posix::wait::Result::no_state_change, core::posix::Process::pid(), core::posix::wait::Result::signal, core::posix::wait::Result::signaled, core::posix::wait::Result::status, and core::posix::wait::Result::stopped.

Referenced by TEST(), TEST(), and TEST().

Here is the call graph for this function:

## Friends And Related Symbol Documentation

## fork

ChildProcess fork | ( | const std::function< posix::exit::Status()> & | main,
|  | const StandardStream & | flags )

friend

fork forks a new process and executes the provided main function in the newly forked process.

Exceptions

  std::system_error | in case of errors.

Parameters

  [in] | main | The main function of the newly forked process.
  [in] | flags | Specify which standard streams should be redirected to the parent process.

Returns
  An instance of ChildProcess in case of success.

Definition at line 57 of file fork.cpp.

References core::posix::empty, core::posix::exit::failure, core::posix::fork(), core::posix::is_child(), main(), core::posix::Process::pid(), core::posix::stderr, core::posix::stdin, and core::posix::stdout.

## vfork

ChildProcess vfork | ( | const std::function< posix::exit::Status()> & | main,
|  | const StandardStream & | flags )

friend

fork vforks a new process and executes the provided main function in the newly forked process.

Exceptions

  std::system_error | in case of errors.

Parameters

  [in] | main | The main function of the newly forked process.
  [in] | flags | Specify which standard streams should be redirected to the parent process.

Returns
  An instance of ChildProcess in case of success.

Definition at line 125 of file fork.cpp.

References core::posix::empty, core::posix::exit::failure, core::posix::is_child(), main(), core::posix::Process::pid(), core::posix::stderr, core::posix::stdin, core::posix::stdout, and core::posix::vfork().

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

- child_process.h
- child_process.cpp