#include <process.hh>
Classes | |
class | already_running |
struct | output_file |
Public Types | |
enum | Stream { Stdout = 1, Stderr = 2, Stdout = 1, Stderr = 2 } |
enum | Stream { Stdout = 1, Stderr = 2, Stdout = 1, Stderr = 2 } |
Public Member Functions | |
void | clear () |
void | clear () |
void | clear_environment () |
void | clear_environment () |
std::list< std::string > | cmdline () const |
std::list< std::string > | cmdline () const |
void | detach () |
void | detach () |
std::string | environment (const std::string &key) const |
std::string | environment (const std::string &key) const |
void | erase_redirection (Stream stream) |
void | erase_redirection (Stream stream) |
bool | exit_normal () const |
bool | exit_normal () const |
int | exit_status () const |
int | exit_status () const |
process & | operator<< (std::string const &newarg) |
process & | operator<< (std::string const &newarg) |
pid_t | pid () const |
pid_t | pid () const |
process () | |
process () | |
void | push (const std::string &arg) |
void | push (const std::string &arg) |
void | redirect_to (Stream stream, boost::filesystem::path const &file) |
void | redirect_to (Stream stream, FILE *handle, bool auto_close=true) |
void | redirect_to (Stream stream, int handle, bool auto_close=true) |
void | redirect_to (Stream stream, boost::filesystem::path const &file) |
void | redirect_to (Stream stream, FILE *handle, bool auto_close=true) |
void | redirect_to (Stream stream, int handle, bool auto_close=true) |
bool | running () |
bool | running () |
void | set_environment (const std::string &key, const std::string &value) |
void | set_environment (const std::string &key, const std::string &value) |
void | set_pgid (pid_t pid) |
void | set_pgid (pid_t pid) |
void | set_workdir (boost::filesystem::path const &dir) |
void | set_workdir (boost::filesystem::path const &dir) |
void | signal (int signo=SIGINT) |
void | signal (int signo=SIGINT) |
void | start () |
void | start () |
void | wait () |
void | wait () |
boost::filesystem::path | workdir () const |
boost::filesystem::path | workdir () const |
~process () | |
~process () | |
Static Public Member Functions | |
static void | install_sigint_handler () |
static void | install_sigint_handler () |
static void | killall () |
static void | killall () |
Static Public Attributes | |
static const int | InvalidHandle = -1 |
Private Types | |
typedef std::list< std::string > | CommandLine |
typedef std::list< std::string > | CommandLine |
typedef std::map< std::string, std::string > | Env |
typedef std::map< std::string, std::string > | Env |
typedef std::list< process * > ::iterator | ProcessHandle |
typedef std::list< process * > ::iterator | ProcessHandle |
Private Member Functions | |
output_file & | get_stream (Stream stream) |
output_file & | get_stream (Stream stream) |
void | process_child_error (int fd) |
void | process_child_error (int fd) |
void | send_child_error (int fd, int error_type) |
void | send_child_error (int fd, int error_type) |
bool | wait (bool hang) |
bool | wait (bool hang) |
Private Attributes | |
CommandLine | m_cmdline |
bool | m_do_setpgid |
Env | m_env |
ProcessHandle | m_handle |
bool | m_normalexit |
pid_t | m_pgid |
pid_t | m_pid |
bool | m_running |
int | m_status |
output_file | m_stderr |
output_file | m_stdout |
boost::filesystem::path | m_wdir |
An external process
Definition at line 11 of file install/include/utilmm/system/process.hh.
typedef std::list<std::string> utilmm::process::CommandLine [private] |
Definition at line 32 of file utilmm/system/process.hh.
typedef std::list<std::string> utilmm::process::CommandLine [private] |
Definition at line 16 of file install/include/utilmm/system/process.hh.
typedef std::map<std::string, std::string> utilmm::process::Env [private] |
Definition at line 35 of file utilmm/system/process.hh.
typedef std::map<std::string, std::string> utilmm::process::Env [private] |
Definition at line 19 of file install/include/utilmm/system/process.hh.
typedef std::list<process*>::iterator utilmm::process::ProcessHandle [private] |
Definition at line 28 of file utilmm/system/process.hh.
typedef std::list<process*>::iterator utilmm::process::ProcessHandle [private] |
Definition at line 12 of file install/include/utilmm/system/process.hh.
Definition of the streams we can redirect to
Definition at line 25 of file utilmm/system/process.hh.
Definition of the streams we can redirect to
Definition at line 9 of file install/include/utilmm/system/process.hh.
process::process | ( | ) |
Definition at line 102 of file process.cc.
process::~process | ( | ) |
Definition at line 107 of file process.cc.
utilmm::process::process | ( | ) |
utilmm::process::~process | ( | ) |
void utilmm::process::clear | ( | ) |
Clear the command line
void process::clear | ( | ) |
Clear the command line
Definition at line 128 of file process.cc.
void utilmm::process::clear_environment | ( | ) |
Remove any overriden environment variable
void process::clear_environment | ( | ) |
Remove any overriden environment variable
Definition at line 356 of file process.cc.
std::list<std::string> utilmm::process::cmdline | ( | ) | const |
Get the list of elements in the command line. It includes the process name.
list< string > process::cmdline | ( | ) | const |
Get the list of elements in the command line. It includes the process name.
Definition at line 121 of file process.cc.
void utilmm::process::detach | ( | ) |
Detach from a running process Call this to make the process object forget about a running child.
After a call to detach(), the child process won't be stopped when this object is destroyed
void process::detach | ( | ) |
Detach from a running process Call this to make the process object forget about a running child.
After a call to detach(), the child process won't be stopped when this object is destroyed
Definition at line 290 of file process.cc.
std::string utilmm::process::environment | ( | const std::string & | key | ) | const |
Gets an overriden environment variable
key | the variable name |
key
has previously been overriden by a call to process::set_environment std::string process::environment | ( | const std::string & | key | ) | const |
Gets an overriden environment variable
key | the variable name |
key
has previously been overriden by a call to process::set_environment Definition at line 350 of file process.cc.
void utilmm::process::erase_redirection | ( | Stream | stream | ) |
Removes any redirection for stream
stream | the output stream to consider |
void process::erase_redirection | ( | Stream | stream | ) |
Removes any redirection for stream
stream | the output stream to consider |
Definition at line 157 of file process.cc.
bool utilmm::process::exit_normal | ( | ) | const |
Check if the last running process exited normally
bool process::exit_normal | ( | ) | const |
Check if the last running process exited normally
Definition at line 336 of file process.cc.
int utilmm::process::exit_status | ( | ) | const |
Get the exit status of the last running process
int process::exit_status | ( | ) | const |
Get the exit status of the last running process
Definition at line 337 of file process.cc.
output_file& utilmm::process::get_stream | ( | Stream | stream | ) | [private] |
process::output_file & process::get_stream | ( | Stream | stream | ) | [private] |
Definition at line 185 of file process.cc.
static void utilmm::process::install_sigint_handler | ( | ) | [static] |
Install a SIGINT handler which calls process::killall
void process::install_sigint_handler | ( | ) | [static] |
Install a SIGINT handler which calls process::killall
Definition at line 132 of file process.cc.
static void utilmm::process::killall | ( | ) | [static] |
Kill all processes managed by a process instance It is safe to call this inside a signal handler
void process::killall | ( | ) | [static] |
Kill all processes managed by a process instance It is safe to call this inside a signal handler
Definition at line 152 of file process.cc.
process & process::operator<< | ( | std::string const & | newarg | ) |
pid_t utilmm::process::pid | ( | ) | const |
Get the PID of the last running process
pid_t process::pid | ( | ) | const |
Get the PID of the last running process
Definition at line 346 of file process.cc.
void utilmm::process::process_child_error | ( | int | fd | ) | [private] |
void process::process_child_error | ( | int | fd | ) | [private] |
Definition at line 271 of file process.cc.
void utilmm::process::push | ( | const std::string & | arg | ) |
Add an element on the command line
void process::push | ( | const std::string & | arg | ) |
Add an element on the command line
Definition at line 122 of file process.cc.
void utilmm::process::redirect_to | ( | Stream | stream, | |
boost::filesystem::path const & | file | |||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void utilmm::process::redirect_to | ( | Stream | stream, | |
FILE * | handle, | |||
bool | auto_close = true | |||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void utilmm::process::redirect_to | ( | Stream | stream, | |
int | handle, | |||
bool | auto_close = true | |||
) |
Redirects the program output to a file or an already opened file descriptor
process prs; tempfile tmp("basename"); prs.redirect_to(process::Stdout, tmp.fd(), true);
process prs; prs.redirect_to(process::Stdout, "my_output_file");
stream | the output stream, either StdOut or StdErr | |
handle | the file handle to redirect to, or InvalidHandle | |
auto_close | if the file descriptor is owned by this object. If this flag is true, there is no more guarantee as to the status of the file descriptor. It can be closed anytime by the process object |
void process::redirect_to | ( | Stream | stream, | |
boost::filesystem::path const & | file | |||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 158 of file process.cc.
void process::redirect_to | ( | Stream | stream, | |
FILE * | handle, | |||
bool | auto_close = true | |||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 167 of file process.cc.
void process::redirect_to | ( | Stream | stream, | |
int | handle, | |||
bool | auto_close = true | |||
) |
Redirects the program output to a file or an already opened file descriptor
process prs; tempfile tmp("basename"); prs.redirect_to(process::Stdout, tmp.fd(), true);
process prs; prs.redirect_to(process::Stdout, "my_output_file");
stream | the output stream, either StdOut or StdErr | |
handle | the file handle to redirect to, or InvalidHandle | |
auto_close | if the file descriptor is owned by this object. If this flag is true, there is no more guarantee as to the status of the file descriptor. It can be closed anytime by the process object |
Definition at line 174 of file process.cc.
bool utilmm::process::running | ( | ) |
Check if the process is running
bool process::running | ( | ) |
Check if the process is running
Definition at line 338 of file process.cc.
void utilmm::process::send_child_error | ( | int | fd, | |
int | error_type | |||
) | [private] |
void process::send_child_error | ( | int | fd, | |
int | error_type | |||
) | [private] |
Definition at line 282 of file process.cc.
void utilmm::process::set_environment | ( | const std::string & | key, | |
const std::string & | value | |||
) |
Override an environment variable This function sets or overrides an environment variable for the subprocess.
key | the variable name | |
value | the variable value |
void process::set_environment | ( | const std::string & | key, | |
const std::string & | value | |||
) |
Override an environment variable This function sets or overrides an environment variable for the subprocess.
key | the variable name | |
value | the variable value |
Definition at line 348 of file process.cc.
void utilmm::process::set_pgid | ( | pid_t | pid | ) |
Set the process group ID at startup. See setpgid(3)
void process::set_pgid | ( | pid_t | pid | ) |
Set the process group ID at startup. See setpgid(3)
Definition at line 198 of file process.cc.
void utilmm::process::set_workdir | ( | boost::filesystem::path const & | dir | ) |
Set the working directory
void process::set_workdir | ( | boost::filesystem::path const & | dir | ) |
Set the working directory
Definition at line 118 of file process.cc.
void utilmm::process::signal | ( | int | signo = SIGINT |
) |
Send a signal to a running process
unix_error | an error occured |
void process::signal | ( | int | signo = SIGINT |
) |
Send a signal to a running process
unix_error | an error occured |
Definition at line 295 of file process.cc.
void utilmm::process::start | ( | ) |
Start the process
unix_error | an error occured while starting the process | |
already_running | this process object has already started |
void process::start | ( | ) |
Start the process
unix_error | an error occured while starting the process | |
already_running | this process object has already started |
Definition at line 206 of file process.cc.
void utilmm::process::wait | ( | ) |
Wait for the process to terminate Use running() to check if the process is running or not
bool utilmm::process::wait | ( | bool | hang | ) | [private] |
void process::wait | ( | ) |
Wait for the process to terminate Use running() to check if the process is running or not
Definition at line 307 of file process.cc.
bool process::wait | ( | bool | hang | ) | [private] |
Definition at line 308 of file process.cc.
boost::filesystem::path utilmm::process::workdir | ( | ) | const |
Get the working directory
boost::filesystem::path process::workdir | ( | ) | const |
Get the working directory
Definition at line 117 of file process.cc.
static const int utilmm::process::InvalidHandle = -1 [static] |
Definition at line 7 of file install/include/utilmm/system/process.hh.
CommandLine utilmm::process::m_cmdline [private] |
Definition at line 17 of file install/include/utilmm/system/process.hh.
bool utilmm::process::m_do_setpgid [private] |
Definition at line 35 of file install/include/utilmm/system/process.hh.
Env utilmm::process::m_env [private] |
Definition at line 20 of file install/include/utilmm/system/process.hh.
ProcessHandle utilmm::process::m_handle [private] |
Definition at line 13 of file install/include/utilmm/system/process.hh.
bool utilmm::process::m_normalexit [private] |
Definition at line 32 of file install/include/utilmm/system/process.hh.
pid_t utilmm::process::m_pgid [private] |
Definition at line 36 of file install/include/utilmm/system/process.hh.
pid_t utilmm::process::m_pid [private] |
Definition at line 31 of file install/include/utilmm/system/process.hh.
bool utilmm::process::m_running [private] |
Definition at line 30 of file install/include/utilmm/system/process.hh.
int utilmm::process::m_status [private] |
Definition at line 33 of file install/include/utilmm/system/process.hh.
output_file utilmm::process::m_stderr [private] |
Definition at line 27 of file install/include/utilmm/system/process.hh.
output_file utilmm::process::m_stdout [private] |
Definition at line 27 of file install/include/utilmm/system/process.hh.
boost::filesystem::path utilmm::process::m_wdir [private] |
Definition at line 15 of file install/include/utilmm/system/process.hh.