Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Private Attributes
Process Class Reference

A class for containing portable process related functions that help create portable code. More...

#include <process.h>

Collaboration diagram for Process:
Collaboration graph
[legend]

Public Types

typedef RETSIGTYPE(* Trap )(int)
 

Public Member Functions

bool lock (bool future=true)
 Lock a process in memory. More...
 
void unlock (void)
 Unlock process pages. More...
 

Static Public Member Functions

static void detach (void)
 Detach current process into a daemon, posix only. More...
 
static void attach (const char *devname)
 Attach the current process to another device or i/o session. More...
 
static Trap setPosixSignal (int signo, Trap handler)
 Set a posix compliant signal handler. More...
 
static Trap setInterruptSignal (int signo, Trap handler)
 Set system call interuptable signal handler. More...
 
static int spawn (const char *exec, const char **argv, bool wait=true)
 Spawn a process and wait for it's exit code. More...
 
static int join (int pid)
 Get the exit status of another process, waiting for it to exit. More...
 
static bool cancel (int pid, int sig=0)
 Cancel a running child process. More...
 
static const char * getEnv (const char *name)
 Get system environment. More...
 
static void setEnv (const char *name, const char *value, bool overwrite)
 Set system environment in a standard manner. More...
 
static const char * getConfigDir (void)
 Get etc prefix path. More...
 
static const char * getHomeDir (void)
 Get home directory. More...
 
static const char * getUser (void)
 Get user name. More...
 
static bool setUser (const char *id, bool grp=true)
 Set user id by name. More...
 
static bool setGroup (const char *id)
 Set the effective group id by name. More...
 
static size_t getPageSize (void)
 Return the effective operating system page size. More...
 
static void setPriority (int pri)
 Used to set process priority and optionally enable realtime. More...
 
static void setScheduler (const char *policy)
 Used to set process scheduling policy. More...
 
static void setRealtime (int pri=0)
 Portable shortcut for setting realtime... More...
 
static bool isScheduler (void)
 Return true if scheduler settable. More...
 
static bool isRealtime (void)
 Return true if realtime scheduling. More...
 

Static Private Attributes

static bool rtflag
 

Detailed Description

A class for containing portable process related functions that help create portable code.

These are typically referenced thru Process::xxx static member functions. Many of these members are used both for win32 and posix systems although some may be platform specific.

Peocess wrapper class.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

Definition at line 69 of file process.h.

Member Typedef Documentation

typedef RETSIGTYPE(* Process::Trap)(int)

Definition at line 76 of file process.h.

Member Function Documentation

static void Process::attach ( const char *  devname)
static

Attach the current process to another device or i/o session.

It is deamonified and dissasociated with the prior parent process and controlling terminal.

Parameters
devnamepath to attach to.
static bool Process::cancel ( int  pid,
int  sig = 0 
)
static

Cancel a running child process.

Returns
0 on success.
Parameters
pidprocess id.
sigcancel signal to apply.
static void Process::detach ( void  )
static

Detach current process into a daemon, posix only.

Perhaps a similar method can be used for creating win32 "services"?

static const char* Process::getConfigDir ( void  )
static

Get etc prefix path.

Returns
etc prefix.
static const char* Process::getEnv ( const char *  name)
static

Get system environment.

Returns
system environ symbol.
Parameters
nameof symbol.
static const char* Process::getHomeDir ( void  )
static

Get home directory.

Returns
user home directory.
static size_t Process::getPageSize ( void  )
static

Return the effective operating system page size.

Returns
system page size.
static const char* Process::getUser ( void  )
static

Get user name.

Returns
user login id.
static bool Process::isRealtime ( void  )
inlinestatic

Return true if realtime scheduling.

Definition at line 246 of file process.h.

static bool Process::isScheduler ( void  )
static

Return true if scheduler settable.

static int Process::join ( int  pid)
static

Get the exit status of another process, waiting for it to exit.

Returns
exit code from process.
Parameters
pidprocess id.
bool Process::lock ( bool  future = true)

Lock a process in memory.

Ideally you should be deep enough where additional memallocs for functions will not kill you, or use false for future.

Returns
true if successful.
Parameters
futurepages as well...
static void Process::setEnv ( const char *  name,
const char *  value,
bool  overwrite 
)
static

Set system environment in a standard manner.

Parameters
nameof environment symbol to set.
valueof environment symbol.
overwritetrue if replace existing symbol.
static bool Process::setGroup ( const char *  id)
static

Set the effective group id by name.

Returns
true if successful.
static Trap Process::setInterruptSignal ( int  signo,
Trap  handler 
)
static

Set system call interuptable signal handler.

#return previous handler.

Parameters
signosignal no.
handlertrap handler.
static Trap Process::setPosixSignal ( int  signo,
Trap  handler 
)
static

Set a posix compliant signal handler.

Returns
previous handler.
Parameters
signosignal no.
handlertrap handler.
static void Process::setPriority ( int  pri)
static

Used to set process priority and optionally enable realtime.

static void Process::setRealtime ( int  pri = 0)
static

Portable shortcut for setting realtime...

static void Process::setScheduler ( const char *  policy)
static

Used to set process scheduling policy.

static bool Process::setUser ( const char *  id,
bool  grp = true 
)
static

Set user id by name.

Returns
true if successful.
static int Process::spawn ( const char *  exec,
const char **  argv,
bool  wait = true 
)
static

Spawn a process and wait for it's exit code.

In win32 this is done with the spawn system call. In posix, this is done with a fork, an execvp, and a waitpid.

Warning
The implementation differences between posix and win32 systems may cause side effects. For instance, if you use atexit() and this spawn method, on posix systems the function set up with atexit() will be called when the parent process of the fork exits, which will not happen on Win32 systems.
Returns
error code from process.
Parameters
execname of executable.
argvlist of command arguments.
waitfor process to exit before return.
void Process::unlock ( void  )

Unlock process pages.

Field Documentation

bool Process::rtflag
staticprivate

Definition at line 72 of file process.h.


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