Process Class Reference

Simple process management class. More...

#include <process.h>

Collaboration diagram for Process:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Process ()
virtual ~Process ()
std::string Start (char *file, char **argv)
 Starts the subprocess.
std::string Fork ()
 Fork the current process.
int GetPID ()
 Get the pidof of the subprocess.
int GetExitCode ()
 Read the exit status of the subprocess.
std::string GetOutput (char *buf, unsigned int &len, int &fd)
 Read from standard outputs of the subprocess.
std::string SendStdin (char *buf, int len)
 Send data to the standard input of the subprocess.
void SendStdinClose ()
 Closes the standard input of the subprocess.

Protected Member Functions

virtual std::string ParentOnFork ()
 Call from the parent process after when the process is forking.
virtual std::string ChildOnFork ()
 Call from the child process after when the process is forking.
virtual std::string HandleEvents ()
 Handle events of the process.

Protected Attributes

int exit_code
pid_t pid


Detailed Description

Simple process management class.

Allows to start a subprocess asynchronously. Provide some methods to read and write to the subprocess standard input / output

Definition at line 12 of file process.h.


Constructor & Destructor Documentation

Process::Process (  ) 

Definition at line 13 of file process.cpp.

Process::~Process (  )  [virtual]

Definition at line 28 of file process.cpp.


Member Function Documentation

virtual std::string Process::ChildOnFork (  )  [inline, protected, virtual]

Call from the child process after when the process is forking.

Called from the Start and Fork methods.

Returns:
an empty string on success or an error string in case of error.

Definition at line 38 of file process.h.

std::string Process::Fork (  ) 

Fork the current process.

Returns:
an empty string on success or an error string in case of error.

Definition at line 80 of file process.cpp.

int Process::GetExitCode (  ) 

Read the exit status of the subprocess.

Returns:
the exit status of the subprocess or -1 when no subprocess has been started or if it's still running.

Definition at line 172 of file process.cpp.

std::string Process::GetOutput ( char *  buf,
unsigned int &  len,
int &  fd 
)

Read from standard outputs of the subprocess.

The standard output (stdout and stderr) are checked for available data. This method is non bloquant.

Parameters:
buf pointer to buffer where to store the output.
len unsigned integer specifying the size of the passed buffer. It contains the number of characters read when the call returns.
fd is not used on input. It contains the file descriptor that had output data (1 for stdout, 2 for stderr) when the call returns.
Returns:
an empty string on success or an error string in case of error.

Definition at line 101 of file process.cpp.

int Process::GetPID (  ) 

Get the pidof of the subprocess.

Returns:
the pidof of the subprocess or 0 if no subprocess has been started.

Definition at line 96 of file process.cpp.

std::string Process::HandleEvents (  )  [protected, virtual]

Handle events of the process.

Should update the exit_code member. Called from the GetOutput and SendStdin methods.

Returns:
an empty string on success or an error string in case of error.

Definition at line 194 of file process.cpp.

virtual std::string Process::ParentOnFork (  )  [inline, protected, virtual]

Call from the parent process after when the process is forking.

Called from the Start and Fork methods.

Returns:
an empty string on success or an error string in case of error.

Definition at line 30 of file process.h.

std::string Process::SendStdin ( char *  buf,
int  len 
)

Send data to the standard input of the subprocess.

Parameters:
buf Input buffer to send.
len Size of the buffer to pass.
Returns:
an empty string on success or an error string in case of error.

Definition at line 177 of file process.cpp.

void Process::SendStdinClose (  ) 

Closes the standard input of the subprocess.

Trigger an end of file on the standard input of the subprocess.

Definition at line 189 of file process.cpp.

std::string Process::Start ( char *  file,
char **  argv 
)

Starts the subprocess.

Arguments to this method are passed unmodified to the execvp syscall.

Parameters:
file path to the binary file to execute.
argv array of null terminated strings passed as arguments to the command. The last element of the array must be a NULL pointer.
Returns:
an empty string on success or an error string in case of error.

Definition at line 38 of file process.cpp.


Member Data Documentation

int Process::exit_code [protected]

Definition at line 21 of file process.h.

pid_t Process::pid [protected]

Definition at line 22 of file process.h.


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

Generated on Sun Nov 29 15:25:19 2009 for libprocess by  doxygen 1.5.8