Util--  1.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
utilmm::process Class Reference

#include <utilmm/system/process.hh>

Classes

class  already_running
 

Public Types

enum  Stream { Stdout = 1, Stderr = 2 }
 

Public Member Functions

 process ()
 
 ~process ()
 
void set_workdir (boost::filesystem::path const &dir)
 
boost::filesystem::path workdir () const
 
std::list< std::string > cmdline () const
 
void push (const std::string &arg)
 
processoperator<< (std::string const &newarg)
 
void clear ()
 
void start ()
 
void signal (int signo=SIGINT)
 
void wait ()
 
void detach ()
 
void erase_redirection (Stream stream)
 
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)
 
void set_environment (const std::string &key, const std::string &value)
 
std::string environment (const std::string &key) const
 
void clear_environment ()
 
void set_pgid (pid_t pid)
 
bool exit_normal () const
 
int exit_status () const
 
pid_t pid () const
 
bool running ()
 

Static Public Member Functions

static void install_sigint_handler ()
 
static void killall ()
 

Static Public Attributes

static const int InvalidHandle = -1
 

Detailed Description

An external process

Author
Sylvain Joyeux sylva.nosp@m.in.j.nosp@m.oyeux.nosp@m.@laa.nosp@m.s.fr

Member Enumeration Documentation

◆ Stream

Definition of the streams we can redirect to

Enumerator
Stdout 
Stderr 

Constructor & Destructor Documentation

◆ process()

utilmm::process::process ( )

◆ ~process()

utilmm::process::~process ( )

Member Function Documentation

◆ clear()

void utilmm::process::clear ( )

Clear the command line

◆ clear_environment()

void utilmm::process::clear_environment ( )

Remove any overriden environment variable

◆ cmdline()

std::list<std::string> utilmm::process::cmdline ( ) const

Get the list of elements in the command line. It includes the process name.

◆ detach()

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

◆ environment()

std::string utilmm::process::environment ( const std::string &  key) const

Gets an overriden environment variable

Parameters
keythe variable name
Returns
the variable value if key has previously been overriden by a call to process::set_environment

◆ erase_redirection()

void utilmm::process::erase_redirection ( Stream  stream)

Removes any redirection for stream

Parameters
streamthe output stream to consider

◆ exit_normal()

bool utilmm::process::exit_normal ( ) const

Check if the last running process exited normally

◆ exit_status()

int utilmm::process::exit_status ( ) const

Get the exit status of the last running process

◆ install_sigint_handler()

static void utilmm::process::install_sigint_handler ( )
static

Install a SIGINT handler which calls process::killall

◆ killall()

static void utilmm::process::killall ( )
static

Kill all processes managed by a process instance It is safe to call this inside a signal handler

◆ operator<<()

process& utilmm::process::operator<< ( std::string const &  newarg)

An alias to push

See also
push

◆ pid()

pid_t utilmm::process::pid ( ) const

Get the PID of the last running process

◆ push()

void utilmm::process::push ( const std::string &  arg)

Add an element on the command line

◆ redirect_to() [1/3]

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

Using temporary files
process prs;
tempfile tmp("basename");
prs.redirect_to(process::Stdout, tmp.fd(), true);
Make the object open a file
process prs;
prs.redirect_to(process::Stdout, "my_output_file");
Parameters
streamthe output stream, either StdOut or StdErr
handlethe file handle to redirect to, or InvalidHandle
auto_closeif 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

◆ redirect_to() [2/3]

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.

◆ redirect_to() [3/3]

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.

◆ running()

bool utilmm::process::running ( )

Check if the process is running

◆ set_environment()

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.

Parameters
keythe variable name
valuethe variable value

◆ set_pgid()

void utilmm::process::set_pgid ( pid_t  pid)

Set the process group ID at startup. See setpgid(3)

◆ set_workdir()

void utilmm::process::set_workdir ( boost::filesystem::path const &  dir)

Set the working directory

◆ signal()

void utilmm::process::signal ( int  signo = SIGINT)

Send a signal to a running process

  • signo specify the signal to send to the process
    Returns
    { true if the signal was sent successfully or if the process was not running, false otherwise. }
    Exceptions
    unix_erroran error occured

◆ start()

void utilmm::process::start ( )

Start the process

Exceptions
unix_erroran error occured while starting the process
already_runningthis process object has already started

◆ wait()

void utilmm::process::wait ( )

Wait for the process to terminate Use running() to check if the process is running or not

◆ workdir()

boost::filesystem::path utilmm::process::workdir ( ) const

Get the working directory

Returns
the value set by set_workdir, or an empty string

Member Data Documentation

◆ InvalidHandle

const int utilmm::process::InvalidHandle = -1
static

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

Generated on Mon Oct 22 2018 18:39:28 for Util-- by doxygen 1.8.13
SourceForge.net Project Page