Fawkes API Fawkes Development Version
fawkes::SubProcess Class Reference

Sub-process execution with stdin/stdout/stderr redirection. More...

#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 36 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 55 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 81 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 107 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 144 of file proc.cpp.

◆ ~SubProcess()

fawkes::SubProcess::~SubProcess ( )

Destructor.

Definition at line 177 of file proc.cpp.

References kill().

Member Function Documentation

◆ alive()

bool fawkes::SubProcess::alive ( )

Check if process is alive.

Returns
true if process is alive, false otherwise

Definition at line 353 of file proc.cpp.

References check_proc().

Referenced by exit_status().

◆ check_proc()

void fawkes::SubProcess::check_proc ( )

Check if the process is still alive.

Definition at line 375 of file proc.cpp.

References fawkes::Logger::log_error(), and fawkes::Logger::log_warn().

Referenced by alive(), and 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 365 of file proc.cpp.

References alive().

◆ kill()

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

Send a signal to the process.

Parameters
signumsignal number

Definition at line 188 of file proc.cpp.

References kill().

Referenced by OpenPRSThread::finalize(), kill(), and ~SubProcess().

◆ pid()

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

Get PID of sub-process.

Returns
process ID of sub-process.

Definition at line 59 of file proc.h.

◆ 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 83 of file proc.h.

◆ 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 67 of file proc.h.

◆ 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 75 of file proc.h.

◆ 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 107 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 91 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 99 of file proc.h.


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