Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

atoms::Process Class Reference

#include <process.hh>

Collaboration diagram for atoms::Process:

Collaboration graph
[legend]
List of all members.

Detailed Description

Represents a UNIX process on the local machine.

Definition at line 26 of file process.hh.

Public Member Functions

 Process (pid_t pid)
int wait ()
 Waits for the process to exit.


Static Public Member Functions

Process create (const boost::function< int()> &)
 Creates a new process.

void exec (char const *path, char const *const *args, char const *const *environment=NULL)
 Execute a file with the given full path.

void execFollowingPath (char const *name, char const *const *args)
 Execute the named program, following the PATH environment variable.

Process spawn (char const *path, char const *const *args, char const *const *environment=NULL)
 Spawns a new process image with the given full pathname.

Process spawnFollowingPath (char const *name, char const *const *args)
 Spawns a new process image, following the PATH environmental variable.


Static Private Member Functions

Process spawnCommon (const boost::function< int()> &f)
 Common code between spawn and spawnFollowing executed on parent side.

int spawnChildHalf (const boost::shared_ptr< UNIXStream > &writer, const boost::function< int()> &f)
 Common code between spawn and spawnFollowing executed on child side.

void throwExecError (int error)

Private Attributes

pid_t pid

Static Private Attributes

DebugLogger LOGGER


Constructor & Destructor Documentation

atoms::Process::Process pid_t  pid  )  [inline]
 

Definition at line 28 of file process.hh.

References pid.

Referenced by create().


Member Function Documentation

Process Process::create const boost::function< int()> &   )  [static]
 

Creates a new process.

Warning:
Use this with extreme caution when threads have been created. Only the current thread is forked, so the other threads are unlikely to be cleaned up correctly. Most notably, whatever locks they currently hold will be held forever. According to some sources, only async signal-safe interfaces should be called between fork() and exec().

Todo:
correct signal handling

error handling

Definition at line 22 of file process.cc.

References pid, and Process().

Referenced by spawnCommon().

Here is the call graph for this function:

void Process::exec char const *  path,
char const *const *  args,
char const *const *  environment = NULL
[static]
 

Execute a file with the given full path.

The current process image will be replaced with a new one. exec expects a full path; execp follows the PATH environmental variable.

Returns:
No. Successful execution will not return. Unsucessful execution will throw an error.
Exceptions:
Subclasses of Error; to be decided.
See also:
execFollowingPath

Definition at line 38 of file process.cc.

References args, and throwExecError().

Here is the call graph for this function:

void Process::execFollowingPath char const *  name,
char const *const *  args
[static]
 

Execute the named program, following the PATH environment variable.

See also:
exec

Definition at line 45 of file process.cc.

References args, and throwExecError().

Here is the call graph for this function:

Process Process::spawn char const *  path,
char const *const *  args,
char const *const *  environment = NULL
[static]
 

Spawns a new process image with the given full pathname.

This is like doing a create and exec, but the main process waits around to hear about success or failure of the exec.

Todo:
Work out methods for manipulating descriptors.
Exceptions:
Error subclasses as thrown by create and exec.
See also:
create, exec, spawnFollowingPath

For internal use only.

Creates a pipe that will be closed on exec. Success is recognized by immediate closure of the pipe. On failure, the error number is passed through the pipe before closing.

Definition at line 50 of file process.cc.

References args, and spawnCommon().

Here is the call graph for this function:

int Process::spawnChildHalf const boost::shared_ptr< UNIXStream > &  writer,
const boost::function< int()> &  f
[static, private]
 

Common code between spawn and spawnFollowing executed on child side.

Definition at line 85 of file process.cc.

Process Process::spawnCommon const boost::function< int()> &  f  )  [static, private]
 

Common code between spawn and spawnFollowing executed on parent side.

Todo:
Test this with/without SIGCHLD set to SIG_IGN

Definition at line 60 of file process.cc.

References create(), atoms::UNIXStream::Pipe::reader, throwExecError(), wait(), and atoms::UNIXStream::Pipe::writer.

Referenced by spawn(), and spawnFollowingPath().

Here is the call graph for this function:

Process Process::spawnFollowingPath char const *  name,
char const *const *  args
[static]
 

Spawns a new process image, following the PATH environmental variable.

See also:
spawn

Definition at line 56 of file process.cc.

References args, and spawnCommon().

Here is the call graph for this function:

void Process::throwExecError int  error  )  [static, private]
 

Definition at line 106 of file process.cc.

References atoms::DebugLogger::log(), and LOGGER.

Referenced by exec(), execFollowingPath(), and spawnCommon().

Here is the call graph for this function:

int Process::wait  ) 
 

Waits for the process to exit.

Returns:
The exit value; for now use the raw UNIX macros to interpret it.

Todo:

Definition at line 113 of file process.cc.

References pid.

Referenced by spawnCommon().


Member Data Documentation

DebugLogger Process::LOGGER [static, private]
 

Referenced by throwExecError().

pid_t atoms::Process::pid [private]
 

Definition at line 98 of file process.hh.

Referenced by create(), Process(), and wait().


The documentation for this class was generated from the following files:
Generated on Wed Jun 15 01:20:54 2005 for atoms++ by doxygen 1.3.5