Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes
utilmm::process Class Reference

#include <process.hh>

List of all members.

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
processoperator<< (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_fileget_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

Detailed Description

An external process

Author:
Sylvain Joyeux <sylvain.joyeux@laas.fr>

Definition at line 20 of file process.hh.


Member Typedef Documentation

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.


Member Enumeration Documentation

Definition of the streams we can redirect to

Enumerator:
Stdout 
Stderr 

Definition at line 25 of file process.hh.


Constructor & Destructor Documentation

Definition at line 106 of file process.cc.

Definition at line 111 of file process.cc.


Member Function Documentation

void process::clear ( )

Clear the command line

Definition at line 132 of file process.cc.

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

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

Definition at line 362 of file process.cc.

Removes any redirection for stream

Parameters:
streamthe 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.

Definition at line 193 of file process.cc.

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)

An alias to push

See also:
push

Definition at line 127 of file process.cc.

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

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

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.

Parameters:
keythe variable name
valuethe 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

  • 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

Definition at line 307 of file process.cc.

void process::start ( void  )

Start the process

Exceptions:
unix_erroran error occured while starting the process
already_runningthis 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

Returns:
the value set by set_workdir, or an empty string

Definition at line 121 of file process.cc.


Member Data Documentation

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

Definition at line 23 of file process.hh.

Definition at line 33 of file process.hh.

Definition at line 51 of file process.hh.

Definition at line 36 of file process.hh.

Definition at line 29 of file process.hh.

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.

Definition at line 46 of file process.hh.

Definition at line 49 of file process.hh.

Definition at line 43 of file process.hh.

Definition at line 43 of file process.hh.

boost::filesystem::path utilmm::process::m_wdir [private]

Definition at line 31 of file process.hh.


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


utilmm
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Mon Oct 6 2014 03:17:01