#include <process.hh>
Classes | |
class | already_running |
struct | output_file |
Public Types | |
enum | Stream { Stdout = 1, Stderr = 2 } |
Public Member Functions | |
void | clear () |
void | clear_environment () |
std::list< std::string > | cmdline () const |
void | detach () |
std::string | environment (const std::string &key) const |
void | erase_redirection (Stream stream) |
bool | exit_normal () const |
int | exit_status () const |
process & | operator<< (std::string const &newarg) |
pid_t | pid () const |
process () | |
void | push (const std::string &arg) |
void | redirect_to (Stream stream, int handle, bool auto_close=true) |
void | redirect_to (Stream stream, FILE *handle, bool auto_close=true) |
void | redirect_to (Stream stream, boost::filesystem::path const &file) |
bool | running () |
void | set_environment (const std::string &key, const std::string &value) |
void | set_pgid (pid_t pid) |
void | set_workdir (boost::filesystem::path const &dir) |
void | signal (int signo=SIGINT) |
void | start () |
void | wait () |
boost::filesystem::path | workdir () const |
~process () | |
Static Public Member Functions | |
static void | install_sigint_handler () |
static void | killall () |
Static Public Attributes | |
static const int | InvalidHandle = -1 |
Private Types | |
typedef std::list< std::string > | CommandLine |
typedef std::map< std::string, std::string > | Env |
typedef std::list< process * > ::iterator | ProcessHandle |
Private Member Functions | |
output_file & | get_stream (Stream stream) |
void | process_child_error (int fd) |
void | send_child_error (int fd, int error_type) |
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 20 of file process.hh.
typedef std::list<std::string> utilmm::process::CommandLine [private] |
Definition at line 32 of file process.hh.
typedef std::map<std::string, std::string> utilmm::process::Env [private] |
Definition at line 35 of file process.hh.
typedef std::list<process*>::iterator utilmm::process::ProcessHandle [private] |
Definition at line 28 of file process.hh.
Definition of the streams we can redirect to
Definition at line 25 of file process.hh.
process::process | ( | ) |
Definition at line 106 of file process.cc.
Definition at line 111 of file process.cc.
void process::clear | ( | ) |
Clear the command line
Definition at line 132 of file process.cc.
void process::clear_environment | ( | ) |
Remove any overriden environment variable
Definition at line 368 of file process.cc.
list< string > process::cmdline | ( | ) | const |
Get the list of elements in the command line. It includes the process name.
Definition at line 125 of file process.cc.
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 302 of file process.cc.
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 362 of file process.cc.
void process::erase_redirection | ( | Stream | stream | ) |
Removes any redirection for stream
stream | the output stream to consider |
Definition at line 161 of file process.cc.
bool process::exit_normal | ( | ) | const |
Check if the last running process exited normally
Definition at line 348 of file process.cc.
int process::exit_status | ( | ) | const |
Get the exit status of the last running process
Definition at line 349 of file process.cc.
process::output_file & process::get_stream | ( | Stream | stream | ) | [private] |
Definition at line 193 of file process.cc.
void process::install_sigint_handler | ( | ) | [static] |
Install a SIGINT handler which calls process::killall
Definition at line 136 of file process.cc.
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 156 of file process.cc.
process & process::operator<< | ( | std::string const & | newarg | ) |
pid_t process::pid | ( | ) | const |
Get the PID of the last running process
Definition at line 358 of file process.cc.
void process::process_child_error | ( | int | fd | ) | [private] |
Definition at line 283 of file process.cc.
void process::push | ( | const std::string & | arg | ) |
Add an element on the command line
Definition at line 126 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 182 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 175 of file process.cc.
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 162 of file process.cc.
bool process::running | ( | ) |
Check if the process is running
Definition at line 350 of file process.cc.
void process::send_child_error | ( | int | fd, |
int | error_type | ||
) | [private] |
Definition at line 294 of file process.cc.
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 360 of file process.cc.
void process::set_pgid | ( | pid_t | pid | ) |
Set the process group ID at startup. See setpgid(3)
Definition at line 206 of file process.cc.
void process::set_workdir | ( | boost::filesystem::path const & | dir | ) |
Set the working directory
Definition at line 122 of file process.cc.
void process::signal | ( | int | signo = SIGINT | ) |
Send a signal to a running process
unix_error | an error occured |
Definition at line 307 of file process.cc.
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 214 of file process.cc.
bool process::wait | ( | bool | hang | ) | [private] |
Definition at line 320 of file process.cc.
void process::wait | ( | ) |
Wait for the process to terminate Use running() to check if the process is running or not
Definition at line 319 of file process.cc.
boost::filesystem::path process::workdir | ( | ) | const |
Get the working directory
Definition at line 121 of file process.cc.
const int utilmm::process::InvalidHandle = -1 [static] |
Definition at line 23 of file process.hh.
CommandLine utilmm::process::m_cmdline [private] |
Definition at line 33 of file process.hh.
bool utilmm::process::m_do_setpgid [private] |
Definition at line 51 of file process.hh.
Env utilmm::process::m_env [private] |
Definition at line 36 of file process.hh.
ProcessHandle utilmm::process::m_handle [private] |
Definition at line 29 of file process.hh.
bool utilmm::process::m_normalexit [private] |
Definition at line 48 of file process.hh.
pid_t utilmm::process::m_pgid [private] |
Definition at line 52 of file process.hh.
pid_t utilmm::process::m_pid [private] |
Definition at line 47 of file process.hh.
bool utilmm::process::m_running [private] |
Definition at line 46 of file process.hh.
int utilmm::process::m_status [private] |
Definition at line 49 of file process.hh.
output_file utilmm::process::m_stderr [private] |
Definition at line 43 of file process.hh.
output_file utilmm::process::m_stdout [private] |
Definition at line 43 of file process.hh.
boost::filesystem::path utilmm::process::m_wdir [private] |
Definition at line 31 of file process.hh.