process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
core::posix Namespace Reference

Namespaces

 backtrace
 
 exit
 
 linux
 
 this_process
 
 wait
 

Classes

class  ChildProcess
 The Process class models a child process of this process. More...
 
class  Process
 The Process class models a process and possible operations on it. More...
 
class  ProcessGroup
 The ProcessGroup class models a signalable group of process. More...
 
class  Signalable
 The Signalable class abstracts the ability of an entity to be delivered a posix signal. More...
 
class  SignalTrap
 The SignalTrap class encapsulates functionality to trap and handle signals. More...
 

Enumerations

enum  Signal {
  Signal::unknown = 0,
  Signal::sig_hup = SIGHUP,
  Signal::sig_int = SIGINT,
  Signal::sig_quit = SIGQUIT,
  Signal::sig_ill = SIGILL,
  Signal::sig_abrt = SIGABRT,
  Signal::sig_fpe = SIGFPE,
  Signal::sig_kill = SIGKILL,
  Signal::sig_segv = SIGSEGV,
  Signal::sig_pipe = SIGPIPE,
  Signal::sig_alrm = SIGALRM,
  Signal::sig_term = SIGTERM,
  Signal::sig_usr1 = SIGUSR1,
  Signal::sig_usr2 = SIGUSR2,
  Signal::sig_chld = SIGCHLD,
  Signal::sig_cont = SIGCONT,
  Signal::sig_stop = SIGSTOP,
  Signal::sig_tstp = SIGTSTP,
  Signal::sig_ttin = SIGTTIN,
  Signal::sig_ttou = SIGTTOU
}
 The Signal enum collects the most common POSIX signals. More...
 
enum  StandardStream : std::uint8_t {
  StandardStream::empty = 0,
  StandardStream::stdin = 1 << 0,
  StandardStream::stdout = 1 << 1,
  StandardStream::stderr = 1 << 2
}
 The StandardStream enum wraps the POSIX standard streams. More...
 

Functions

CORE_POSIX_DLL_PUBLIC ChildProcess exec (const std::string &fn, const std::vector< std::string > &argv, const std::map< std::string, std::string > &env, const StandardStream &flags)
 exec execve's the executable with the provided arguments and environment. More...
 
CORE_POSIX_DLL_PUBLIC ChildProcess exec (const std::string &fn, const std::vector< std::string > &argv, const std::map< std::string, std::string > &env, const StandardStream &flags, const std::function< void()> &child_setup)
 exec execve's the executable with the provided arguments and environment. More...
 
CORE_POSIX_DLL_PUBLIC 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. More...
 
CORE_POSIX_DLL_PUBLIC 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. More...
 
CORE_POSIX_DLL_PUBLIC std::shared_ptr< SignalTraptrap_signals_for_process (std::initializer_list< core::posix::Signal > blocked_signals)
 Traps the specified signals for the entire process. More...
 
CORE_POSIX_DLL_PUBLIC std::shared_ptr< SignalTraptrap_signals_for_all_subsequent_threads (std::initializer_list< core::posix::Signal > blocked_signals)
 Traps the specified signals for the current thread, and inherits the respective signal mask to all child-threads. More...
 
CORE_POSIX_DLL_PUBLIC StandardStream operator| (StandardStream l, StandardStream r)
 
CORE_POSIX_DLL_PUBLIC StandardStream operator& (StandardStream l, StandardStream r)
 
bool is_child (pid_t pid)
 

Enumeration Type Documentation

enum core::posix::Signal
strong

The Signal enum collects the most common POSIX signals.

Enumerator
unknown 
sig_hup 
sig_int 
sig_quit 
sig_ill 
sig_abrt 
sig_fpe 
sig_kill 
sig_segv 
sig_pipe 
sig_alrm 
sig_term 
sig_usr1 
sig_usr2 
sig_chld 
sig_cont 
sig_stop 
sig_tstp 
sig_ttin 
sig_ttou 

Definition at line 38 of file signal.h.

enum core::posix::StandardStream : std::uint8_t
strong

The StandardStream enum wraps the POSIX standard streams.

Enumerator
empty 
stdin 
stdout 
stderr 

Definition at line 38 of file standard_stream.h.

Function Documentation

ChildProcess core::posix::exec ( const std::string &  fn,
const std::vector< std::string > &  argv,
const std::map< std::string, std::string > &  env,
const StandardStream flags 
)

exec execve's the executable with the provided arguments and environment.

Exceptions
std::system_errorin case of errors.
Parameters
fnThe executable to run.
argvVector of command line arguments
envEnvironment that the new process should run under
flagsSpecifies which standard streams should be redirected.
Returns
An instance of ChildProcess corresponding to the newly exec'd process.

Definition at line 33 of file exec.cpp.

Referenced by TEST().

ChildProcess core::posix::exec ( const std::string &  fn,
const std::vector< std::string > &  argv,
const std::map< std::string, std::string > &  env,
const StandardStream flags,
const std::function< void()> &  child_setup 
)

exec execve's the executable with the provided arguments and environment.

Exceptions
std::system_errorin case of errors.
Parameters
fnThe executable to run.
argvVector of command line arguments
envEnvironment that the new process should run under
flagsSpecifies which standard streams should be redirected.
child_setupFunction to run in the child just before exec().
Returns
An instance of ChildProcess corresponding to the newly exec'd process.

Definition at line 42 of file exec.cpp.

References fork().

+ Here is the call graph for this function:

ChildProcess core::posix::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.

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.

References core::posix::this_process::cerr(), empty, core::posix::exit::failure, is_child(), main(), stderr, stdin, and stdout.

Referenced by exec(), core::testing::fork_and_run(), TEST(), and TEST_F().

+ Here is the call graph for this function:

bool core::posix::is_child ( pid_t  pid)

Definition at line 55 of file fork.cpp.

Referenced by fork(), and vfork().

StandardStream core::posix::operator& ( StandardStream  l,
StandardStream  r 
)

Definition at line 30 of file standard_stream.cpp.

StandardStream core::posix::operator| ( StandardStream  l,
StandardStream  r 
)

Definition at line 25 of file standard_stream.cpp.

std::shared_ptr< core::posix::SignalTrap > core::posix::trap_signals_for_all_subsequent_threads ( std::initializer_list< core::posix::Signal blocked_signals)

Traps the specified signals for the current thread, and inherits the respective signal mask to all child-threads.

Definition at line 210 of file signal.cpp.

References impl::SignalTrap::thread.

std::shared_ptr< core::posix::SignalTrap > core::posix::trap_signals_for_process ( std::initializer_list< core::posix::Signal blocked_signals)

Traps the specified signals for the entire process.

Definition at line 202 of file signal.cpp.

References impl::SignalTrap::process.

ChildProcess core::posix::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.

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 125 of file fork.cpp.

References core::posix::this_process::cerr(), empty, core::posix::exit::failure, is_child(), main(), stderr, stdin, and stdout.

+ Here is the call graph for this function: