process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
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. More...
 
std::istream & cerr ()
 Access this process's stderr. More...
 
std::ostream & cin ()
 Access this process's stdin. More...
 
std::istream & cout ()
 Access this process's stdout. More...
 
- Public Member Functions inherited from core::posix::Process
 Process (pid_t pid)
 Creates a process instance wrapping an existing process. More...
 
virtual ~Process () noexcept
 Frees resources associated with the process. More...
 
virtual pid_t pid () const
 Query the pid of the process. More...
 
virtual ProcessGroup process_group_or_throw () const
 Queries the id of the process group this process belongs to. More...
 
virtual ProcessGroup process_group (std::error_code &se) const noexcept(true)
 Queries the id of the process group this process belongs to. More...
 
- Public Member Functions inherited from core::posix::Signalable
virtual void send_signal_or_throw (Signal signal)
 Sends a signal to this signalable object. More...
 
virtual void send_signal (Signal signal, std::error_code &e) noexcept(true)
 Sends a signal to this signalable object. More...
 

Static Public Member Functions

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

Friends

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

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

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

Definition at line 341 of file child_process.cpp.

Member Function Documentation

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

Access this process's stderr.

Definition at line 382 of file child_process.cpp.

Referenced by TEST().

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

Access this process's stdin.

Definition at line 387 of file child_process.cpp.

Referenced by TEST().

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

Access this process's stdout.

Definition at line 392 of file child_process.cpp.

Referenced by TEST().

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::Result core::posix::ChildProcess::wait_for ( const wait::Flags flags)

Wait for the child process to change state.

Parameters
[in]flagsAlters 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::detail, core::posix::wait::Result::if_exited, core::posix::wait::Result::if_signaled, core::posix::wait::Result::if_stopped, and core::posix::wait::Result::status.

Referenced by TEST(), and TEST_F().

Friends And Related Function Documentation

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_errorin case of errors.
Parameters
[in]mainThe main function of the newly forked process.
[in]flagsSpecify 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.

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_errorin case of errors.
Parameters
[in]mainThe main function of the newly forked process.
[in]flagsSpecify which standard streams should be redirected to the parent process.
Returns
An instance of ChildProcess in case of success.

Definition at line 122 of file fork.cpp.


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