CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Process Class Referencefinal

Process creation and current process state More...

#include <cc/Process>

Inheritance diagram for Process:

Public Member Functions

 Process ()=default
 Create a null sub-process.
 
 Process (const String &command)
 Start a new sub-process executing command (executable path + arguments)
 
 Process (const Command &command)
 Start a new sub-process executing command.
 
int id () const
 Process ID of the sub-process
 
int wait ()
 Wait for sub-process termination and return exit status.
 
IoStream input () const
 Standard input of sub-process.
 
IoStream output () const
 Standard output of sub-process.
 
IoStream error () const
 Standard error of sub-process.
 
- Public Member Functions inherited from Object
 Object ()=default
 Create a null object.
 
 operator bool () const
 Check if this is a non-null object.
 
bool isNull () const
 Check if this is a null object.
 
template<class T >
bool is () const
 Check if this object is of type T.
 
template<class T >
as () const
 Cast this object to type T.
 
bool isWeak () const
 Check if the underlying object reference is weak.
 
bool operator== (const Object &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Object &other) const
 Ordering operator.
 
long useCount () const
 Reference count.
 

Static Public Member Functions

static int exec (const String &command)
 Start process and wait for its completion (convenience method)
 
static int exec (const List< String > &args)
 Start process and wait for its completion (convenience method)
 
static bool isSignaled (int status)
 Check if exit status indicates termination by an unhandled signal.
 
static Signal signalNumber (int status)
 Translate status to signal number.
 
static void kill (int pid, Signal signal=Signal::Terminate)
 Send signal to process with ID pid.
 
static void killGroup (int gid, Signal signal=Signal::Terminate)
 Send signal to process group with ID gid.
 
static void raise (Signal signal)
 Send a signal to the calling process.
 
static void exit (int status)
 Terminate this process with exit code status [0, 255].
 
static int currentId ()
 Get current process ID.
 
static int parentId ()
 Get parent process ID.
 
static String execPath ()
 Get the file path of the currently running executable.
 
static String env (const String &name)
 Get environment variable by name.
 
static String env (const String &name, const String &fallback)
 Get environment variable by name and if undefined return fallback.
 
static void setEnv (const String &name, const String &value)
 Set environment variable name to value
 
static void unsetEnv (const String &name)
 Unset environment variable name to an undefined value.
 
static Map< StringenvMap ()
 Get the current environment map.
 
static String cwd ()
 Get the current working directory.
 
static void cd (const String &path)
 Set the current working directory to path
 
static void setUserMask (FileMode newMask, Out< FileMode > oldMask=None{})
 Set the file mode creation mask to newMask and optionally return the old mask in oldMask
 
static int realUserId ()
 Get the real user ID.
 
static int realGroupId ()
 Get the real group ID.
 
static int effectiveUserId ()
 Get the effective user ID.
 
static int effectiveGroupId ()
 Get the effective group ID.
 
static bool isSuperUser ()
 Check for super-user.
 
static void setUserId (int uid)
 Set user ID to uid
 
static void setGroupId (int gid)
 Set the group ID to gid
 
static void setEffectiveUserId (int uid)
 Set the effective user ID to uid
 
static void setEffectiveGroupId (int gid)
 Set the effective group ID to gid
 
static void daemonize ()
 Daemonize this process.
 
static bool isDaemonized ()
 Check if daemonized.
 
static void startSession ()
 Start a new login session.
 

Additional Inherited Members

- Protected Member Functions inherited from Object
template<class T >
weak () const
 
template<class T >
void initOnce ()
 Create the object state when called the first time.
 
template<class T >
void initOncePerThread ()
 Create a distinct object state for each thread when called the first time in that thread.
 
 Object (State *newState)
 Initialize object with newState.
 
 Object (State *state, Alias)
 
 Object (State *state, Weak)
 
Objectoperator= (std::nullptr_t)
 
- Static Protected Member Functions inherited from Object
template<class T >
static T alias (const State *state)
 Create an alias object for the given state.
 
template<class T >
static T weak (const State *state)
 
- Protected Attributes inherited from Object
Handle< Stateme
 Internal object state
 

Detailed Description

Process creation and current process state

Exceptions
SystemError

Constructor & Destructor Documentation

◆ Process() [1/3]

Process ( )
default

Create a null sub-process.

◆ Process() [2/3]

Process ( const String & command)
explicit

Start a new sub-process executing command (executable path + arguments)

◆ Process() [3/3]

Process ( const Command & command)
explicit

Start a new sub-process executing command.

Member Function Documentation

◆ exec() [1/2]

int exec ( const String & command)
static

Start process and wait for its completion (convenience method)

◆ exec() [2/2]

int exec ( const List< String > & args)
static

Start process and wait for its completion (convenience method)

◆ id()

int id ( ) const

Process ID of the sub-process

◆ wait()

int wait ( )

Wait for sub-process termination and return exit status.

◆ input()

IoStream input ( ) const

Standard input of sub-process.

◆ output()

IoStream output ( ) const

Standard output of sub-process.

◆ error()

IoStream error ( ) const

Standard error of sub-process.

◆ isSignaled()

static bool isSignaled ( int status)
static

Check if exit status indicates termination by an unhandled signal.

◆ signalNumber()

static Signal signalNumber ( int status)
static

Translate status to signal number.

◆ kill()

void kill ( int pid,
Signal signal = Signal::Terminate )
static

Send signal to process with ID pid.

◆ killGroup()

void killGroup ( int gid,
Signal signal = Signal::Terminate )
static

Send signal to process group with ID gid.

◆ raise()

void raise ( Signal signal)
static

Send a signal to the calling process.

◆ exit()

void exit ( int status)
static

Terminate this process with exit code status [0, 255].

◆ currentId()

int currentId ( )
static

Get current process ID.

◆ parentId()

int parentId ( )
static

Get parent process ID.

◆ execPath()

String execPath ( )
static

Get the file path of the currently running executable.

◆ env() [1/2]

String env ( const String & name)
static

Get environment variable by name.

◆ env() [2/2]

String env ( const String & name,
const String & fallback )
static

Get environment variable by name and if undefined return fallback.

◆ setEnv()

void setEnv ( const String & name,
const String & value )
static

Set environment variable name to value

◆ unsetEnv()

void unsetEnv ( const String & name)
static

Unset environment variable name to an undefined value.

◆ envMap()

Map< String > envMap ( )
static

Get the current environment map.

◆ cwd()

String cwd ( )
static

Get the current working directory.

◆ cd()

void cd ( const String & path)
static

Set the current working directory to path

◆ setUserMask()

void setUserMask ( FileMode newMask,
Out< FileMode > oldMask = None{} )
static

Set the file mode creation mask to newMask and optionally return the old mask in oldMask

◆ realUserId()

int realUserId ( )
static

Get the real user ID.

◆ realGroupId()

int realGroupId ( )
static

Get the real group ID.

◆ effectiveUserId()

int effectiveUserId ( )
static

Get the effective user ID.

◆ effectiveGroupId()

int effectiveGroupId ( )
static

Get the effective group ID.

◆ isSuperUser()

bool isSuperUser ( )
static

Check for super-user.

◆ setUserId()

void setUserId ( int uid)
static

Set user ID to uid

◆ setGroupId()

void setGroupId ( int gid)
static

Set the group ID to gid

◆ setEffectiveUserId()

void setEffectiveUserId ( int uid)
static

Set the effective user ID to uid

◆ setEffectiveGroupId()

void setEffectiveGroupId ( int gid)
static

Set the effective group ID to gid

◆ daemonize()

void daemonize ( )
static

Daemonize this process.

◆ isDaemonized()

bool isDaemonized ( )
static

Check if daemonized.

◆ startSession()

void startSession ( )
static

Start a new login session.