process


To create, suspend, resume, interrupt, and terminate a process, use the os_process class. When a process object is created, the current process spawns a child and stores the child's PID in the process object.

The current process and its child execute concurrently. To force the current process to wait until one of its child processes terminates, use one of the wait() family of functions described in process_status .

There are several ways to construct a process object.

Each of these approaches has a variation that provides a new environment for the process and performs I/O redirection.

Conversions permit os_process and os_pid_t to be used interchangeably.

Library

Platform<ToolKit> for UNIX

Declaration

#include <ospace/unix/process.h>

class os_process

Interface

Constructor
os_process( const char* name )
Constructs a process object that executes the program name .

Throws: os_unix_toolkit_error

Constructor
os_process( const char* name , const char* argv[] )
Constructs a process object that executes the program name using the null-terminated argument list argv . Terminate the argument list argv with a zero.

Throws: os_unix_toolkit_error

Constructor
os_process( int (*f)() )
Constructs a process object that executes the function f .

Throws: os_unix_toolkit_error

Constructor
os_process( int (*f)( int argc , const char* argv[] ), const char* argv[] )
Constructs a process object that executes the function f using the null-terminated argument list argv . Terminate the argument list argv with a zero.

Throws: os_unix_toolkit_error

Constructor
os_process( const char* shell , const char* command )
Constructs a process object that executes the command command using the shell shell .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , const char* shell , const char* command )
Constructs a process object that executes the command command using the shell shell , environment env , send channel send , receive channel receive , and error channel error .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , const char* name )
Constructs a process object that executes the program name using environment env , send channel send , receive channel receive , and error channel error .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , const char* name , const char* argv[] )
Constructs a process object that executes the program called name using the null-terminated argument list argv , environment env , send channel send , receive channel receive , and error channel error .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , int (*f)() )
Constructs a process object that executes the function f using the environment env , send channel send , receive channel receive , and error channel error .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , int (*f)( int argc , const char* argv[] ), const char* argv[] )
Constructs a process object that executes the function f using the null-terminated argument list argv , environment env , send channel send , receive channel receive , and error channel error .

Throws: os_unix_toolkit_error

Constructor
os_process( const char* name , const char* arg1 , const char* arg2 ,... )
Constructs a process object that executes the program name using the null-terminated variable argument list. Terminate the argument list argv with a zero. The maximum number of arguments is constrained by the enum os_process::max_args .

Throws: os_unix_toolkit_error

Constructor
os_process( int (*f)( int argc , const char* argv[] ), const char* arg0 , const char* arg1 ,... )
Constructs a process object that executes the function f using the null-terminated variable argument list. Terminate the argument list argv with a zero. The maximum number of arguments is constrained by the enum os_process::max_args .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , const char* name , const char* arg1 , const char* arg2 ,... )
Constructs a process object that executes the program name using the null-terminated variable argument list, environment env , send channel send , receive channel receive , and error channel error . Terminate the argument list argv with a zero. The maximum number of arguments is constrained by the enum os_process::max_args .

Throws: os_unix_toolkit_error

Constructor
os_process( const os_environment* env , os_desc_t send , os_desc_t receive , os_desc_t error , int (*f)( int argc , const char* argv[] ), const char* arg0 , const char* arg1 ,... )
Constructs a process object that executes the function f using the null-terminated variable argument list, environment env , send channel send , receive channel receive , and error channel error . Terminate the argument list argv with a zero. The maximum number of arguments is constrained by the enum os_process::max_args .

Throws: os_unix_toolkit_error

Constructor
os_process( os_pid_t pid )
Constructs an object with process ID pid (default OS_UNDEFINED ).
Constructor
os_process( const os_process& process )
Constructs an object that is a copy of process .
<
bool operator<( const os_process& process ) const
Returns true if the process ID is less than process .
=
os_process& operator=( const os_process& process )
Assigns an object from process . Returns a reference to the object.
=
os_process& operator=( os_pid_t process )
Assigns an object from process . Returns a reference to the object.
==
bool operator==( const os_process& process ) const
Returns true if the object has the same process ID as process .
(os_pid_t)
operator os_pid_t() const
Returns the process ID.
become_process_group_leader
void become_process_group_leader()
Makes process a process group leader.

Throws: os_unix_toolkit_error

defined
bool defined() const
Returns true if the process ID is not OS_UNDEFINED . For process activity testing, see valid() .
hangup
void hangup()
Sends process a hangup signal.

Throws: os_unix_toolkit_error

interrupt
void interrupt()
Sends process an interrupt signal.

Throws: os_unix_toolkit_error

is_parent_of_this_process
bool is_parent_of_this_process() const
Returns true if the object is the parent of the current process.
keyboard_suspend
void keyboard_suspend()
Sends process a keyboard stop signal. The stop signal is normally generated by a Ctrl-Z and suspends the execution.

Throws: os_unix_toolkit_error

kill
void kill()
Sends process a kill signal.

Throws: os_unix_toolkit_error

pid
os_pid_t pid() const
Returns the process ID.
pid
void pid( os_pid_t pid )
Sets the process ID to pid .
print
void print( ostream& stream ) const
Prints to stream .
priority
int priority() const
Returns the execution priority (nice) value. The range varies slightly between platforms, but is usually -20 (highest priority) to 20 (lowest priority).

Throws: os_unix_toolkit_error

priority
void priority( int value )
Sets the execution priority (nice) value to value . The range varies between platforms, but is usually -20 (highest priority) to 20 (lowest priority). Only a process with superuser privileges can lower a priority.

Throws: os_unix_toolkit_error

process_group
void process_group( os_pid_t group )
Sets the process group to group .

Throws: os_unix_toolkit_error

process_group
os_pid_t process_group() const
Returns the process group.

Throws: os_unix_toolkit_error

quit
void quit()
Sends process a quit signal.

Throws: os_unix_toolkit_error

resume
void resume()
Sends process a continue signal. This signal resumes the execution, if suspended.

Throws: os_unix_toolkit_error

signal
void signal( os_sig_t signal )
Sends the signal signal .

Throws: os_unix_toolkit_error

suspend
void suspend()
Sends process a stop signal. This suspends execution and is only valid for systems that support job control.

Throws: os_unix_toolkit_error

terminate
void terminate()
Sends process a terminate signal. This is the signal sent by default when the kill(1) UNIX command is executed.

Throws: os_unix_toolkit_error

user_priority
/* static */ void user_priority( os_uid_t user , int value )
Sets the execution priority (nice) value to value for any process owned by user . The range of nice values varies slightly between platforms, but is usually -20 (highest priority) to 20 (lowest priority).

Throws: os_unix_toolkit_error

user_priority
/* static */ int user_priority( os_uid_t user )
Returns the execution priority (nice) value associated with any process owned by user . The range of nice values varies slightly between platforms, but is usually -20 (highest priority) to 20 (lowest priority).

Throws: os_unix_toolkit_error

valid
bool valid() const
Returns true if this process is a valid, registered, UNIX process.

Non-Member Functions

<<
ostream& operator<<( ostream& stream , const os_process& process )
Prints process to stream .

Universal Streaming Service

#include <ospace/uss/unix.h>
<<
os_bstream& operator<<( os_bstream& stream , const os_process& process )
Writes process to stream .
>>
os_bstream& operator>>( os_bstream& stream , os_process& process )
Reads process from stream .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only. - For use by licensed users only.