Fawkes API  Fawkes Development Version
fawkes::SubProcess Class Reference

#include <>>

Public Member Functions

 SubProcess (const char *progname, const char *file, const char *argv[], const char *envp[])
 Constructor. More...
 
 SubProcess (const char *progname, const char *file, const char *argv[], const char *envp[], fawkes::Logger *logger)
 Constructor. More...
 
 SubProcess (const std::string &progname, const std::string &file, const std::vector< std::string > &argv, const std::vector< std::string > &envp)
 Constructor. More...
 
 SubProcess (const std::string &progname, const std::string &file, const std::vector< std::string > &argv, const std::vector< std::string > &envp, fawkes::Logger *logger)
 Constructor. More...
 
 ~SubProcess ()
 Destructor. More...
 
pid_t pid () const
 Get PID of sub-process. More...
 
int pipe_stdin_w () const
 Get stdin pipe file descriptor. More...
 
int pipe_stdout_r () const
 Get stdout pipe file descriptor. More...
 
int pipe_stderr_r () const
 Get stderr pipe file descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stdin ()
 Get stdin stream descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stdout ()
 Get stdout stream descriptor. More...
 
boost::asio::posix::stream_descriptor & sd_stderr ()
 Get stderr stream descriptor. More...
 
void kill (int signum)
 Send a signal to the process. More...
 
void check_proc ()
 Check if the process is still alive. More...
 
bool alive ()
 Check if process is alive. More...
 
int exit_status ()
 Get exit status of process once it ended. More...
 

Detailed Description

Sub-process execution with stdin/stdout/stderr redirection. This class executes a sub-process and monitors it and supports redirecting stdout/stderr to a logger.

Author
Tim Niemueller

Definition at line 42 of file proc.h.

Constructor & Destructor Documentation

◆ SubProcess() [1/4]

fawkes::SubProcess::SubProcess ( const char *  progname,
const char *  file,
const char *  argv[],
const char *  envp[] 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.

Definition at line 60 of file proc.cpp.

◆ SubProcess() [2/4]

fawkes::SubProcess::SubProcess ( const char *  progname,
const char *  file,
const char *  argv[],
const char *  envp[],
fawkes::Logger logger 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.
loggerlogger to redirect stdout and stderr to

Definition at line 86 of file proc.cpp.

◆ SubProcess() [3/4]

fawkes::SubProcess::SubProcess ( const std::string &  progname,
const std::string &  file,
const std::vector< std::string > &  argv,
const std::vector< std::string > &  envp 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.

Definition at line 112 of file proc.cpp.

◆ SubProcess() [4/4]

fawkes::SubProcess::SubProcess ( const std::string &  progname,
const std::string &  file,
const std::vector< std::string > &  argv,
const std::vector< std::string > &  envp,
fawkes::Logger logger 
)

Constructor.

Parameters
prognamename of program, component name for logging
filefile to execute, can be a program in the path or a fully qualified path
argvarray of arguments for the process, the last element must be NULL
envparray of environment variables for the process, the last element must be NULL. Can be NULL to omit.
loggerlogger to redirect stdout and stderr to

Definition at line 149 of file proc.cpp.

◆ ~SubProcess()

fawkes::SubProcess::~SubProcess ( )

Destructor.

Definition at line 182 of file proc.cpp.

Member Function Documentation

◆ alive()

bool fawkes::SubProcess::alive ( )

Check if process is alive.

Returns
true if process is alive, false otherwise

Definition at line 358 of file proc.cpp.

◆ check_proc()

void fawkes::SubProcess::check_proc ( )

Check if the process is still alive.

Definition at line 380 of file proc.cpp.

References fawkes::Logger::log_error().

Referenced by OpenPRSThread::loop().

◆ exit_status()

int fawkes::SubProcess::exit_status ( )

Get exit status of process once it ended.

It is an error to call this on a sub-process which is still alive.

Returns
exit status of process
Exceptions
Exceptionif called while process is still alive

Definition at line 370 of file proc.cpp.

◆ kill()

void fawkes::SubProcess::kill ( int  signum)

Send a signal to the process.

Parameters
signumsignal number

Definition at line 193 of file proc.cpp.

References pid(), pipe_stderr_r(), pipe_stdin_w(), and pipe_stdout_r().

Referenced by OpenPRSThread::finalize().

◆ pid()

pid_t fawkes::SubProcess::pid ( ) const
inline

Get PID of sub-process.

Returns
process ID of sub-process.

Definition at line 65 of file proc.h.

Referenced by kill().

◆ pipe_stderr_r()

int fawkes::SubProcess::pipe_stderr_r ( ) const
inline

Get stderr pipe file descriptor.

Returns
stderr pipe file descriptor, only valid for reading.

Definition at line 89 of file proc.h.

Referenced by kill().

◆ pipe_stdin_w()

int fawkes::SubProcess::pipe_stdin_w ( ) const
inline

Get stdin pipe file descriptor.

Returns
stdin pipe file descriptor, only valid for writing.

Definition at line 73 of file proc.h.

Referenced by kill().

◆ pipe_stdout_r()

int fawkes::SubProcess::pipe_stdout_r ( ) const
inline

Get stdout pipe file descriptor.

Returns
stdout pipe file descriptor, only valid for reading.

Definition at line 81 of file proc.h.

Referenced by kill().

◆ sd_stderr()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stderr ( )
inline

Get stderr stream descriptor.

Returns
stderr stream descriptor, only valid for reading.

Definition at line 113 of file proc.h.

◆ sd_stdin()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stdin ( )
inline

Get stdin stream descriptor.

Returns
stdin stream descriptor, only valid for writing.

Definition at line 97 of file proc.h.

◆ sd_stdout()

boost::asio::posix::stream_descriptor& fawkes::SubProcess::sd_stdout ( )
inline

Get stdout stream descriptor.

Returns
stdout stream descriptor, only valid for reading.

Definition at line 105 of file proc.h.


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