CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | Friends | List of all members
CppCommon::Process Class Reference

Process abstraction. More...

#include <process.h>

Public Member Functions

 Process (const Process &process)
 
 Process (Process &&process) noexcept
 
 ~Process ()
 
Processoperator= (const Process &process)
 
Processoperator= (Process &&process) noexcept
 
uint64_t pid () const noexcept
 Get the process Id. More...
 
bool IsRunning () const
 Is the process is running? More...
 
void Kill ()
 Kill the process. More...
 
int Wait ()
 Wait the process to exit. More...
 
int WaitFor (const Timespan &timespan)
 Wait the process to exit for the given timespan. More...
 
int WaitUntil (const UtcTimestamp &timestamp)
 Wait the process to exit until the given timestamp. More...
 
void swap (Process &process) noexcept
 Swap two instances. More...
 

Static Public Member Functions

static uint64_t CurrentProcessId () noexcept
 Get the current process Id. More...
 
static uint64_t ParentProcessId () noexcept
 Get the parent process Id. More...
 
static Process CurrentProcess ()
 Get the current process. More...
 
static Process ParentProcess ()
 Get the parent process. More...
 
static void Exit (int result)
 Exit the current process. More...
 
static Process Execute (const std::string &command, const std::vector< std::string > *arguments=nullptr, const std::map< std::string, std::string > *envars=nullptr, const std::string *directory=nullptr, Pipe *input=nullptr, Pipe *output=nullptr, Pipe *error=nullptr)
 Execute a new process. More...
 

Friends

void swap (Process &process1, Process &process2) noexcept
 

Detailed Description

Process abstraction.

Process contains different kinds of process manipulation functionality such as retrive the current process Id, execute or terminate one.

Thread-safe.

Examples
system_process.cpp, and system_process_pipes.cpp.

Definition at line 37 of file process.h.

Constructor & Destructor Documentation

◆ Process() [1/2]

CppCommon::Process::Process ( const Process process)

Definition at line 502 of file process.cpp.

◆ Process() [2/2]

CppCommon::Process::Process ( Process &&  process)
noexcept

Definition at line 513 of file process.cpp.

◆ ~Process()

CppCommon::Process::~Process ( )

Definition at line 518 of file process.cpp.

Member Function Documentation

◆ CurrentProcess()

Process CppCommon::Process::CurrentProcess ( )
inlinestatic

Get the current process.

Returns
Current process

Definition at line 11 of file process.inl.

◆ CurrentProcessId()

uint64_t CppCommon::Process::CurrentProcessId ( )
staticnoexcept

Get the current process Id.

Returns
Current process Id
Examples
system_process.cpp.

Definition at line 544 of file process.cpp.

◆ Execute()

Process CppCommon::Process::Execute ( const std::string &  command,
const std::vector< std::string > *  arguments = nullptr,
const std::map< std::string, std::string > *  envars = nullptr,
const std::string *  directory = nullptr,
Pipe input = nullptr,
Pipe output = nullptr,
Pipe error = nullptr 
)
static

Execute a new process.

If input/output/error communication pipe is not provided then new process will use equivalent standard stream of the parent process.

Parameters
command- Command to execute
arguments- Pointer to arguments vector (default is nullptr)
envars- Pointer to environment variables map (default is nullptr)
directory- Initial working directory (default is nullptr)
input- Input communication pipe (default is nullptr)
output- Output communication pipe (default is nullptr)
error- Error communication pipe (default is nullptr)
Returns
Created process
Examples
system_process.cpp, and system_process_pipes.cpp.

Definition at line 549 of file process.cpp.

◆ Exit()

void CppCommon::Process::Exit ( int  result)
static

Exit the current process.

Parameters
result- Result is returned to the parent

Definition at line 547 of file process.cpp.

◆ IsRunning()

bool CppCommon::Process::IsRunning ( ) const

Is the process is running?

Definition at line 538 of file process.cpp.

◆ Kill()

void CppCommon::Process::Kill ( )

Kill the process.

Definition at line 540 of file process.cpp.

◆ operator=() [1/2]

Process & CppCommon::Process::operator= ( const Process process)

Definition at line 524 of file process.cpp.

◆ operator=() [2/2]

Process & CppCommon::Process::operator= ( Process &&  process)
noexcept

Definition at line 530 of file process.cpp.

◆ ParentProcess()

Process CppCommon::Process::ParentProcess ( )
inlinestatic

Get the parent process.

Returns
Parent process

Definition at line 16 of file process.inl.

◆ ParentProcessId()

uint64_t CppCommon::Process::ParentProcessId ( )
staticnoexcept

Get the parent process Id.

Returns
Parent process Id
Examples
system_process.cpp.

Definition at line 545 of file process.cpp.

◆ pid()

uint64_t CppCommon::Process::pid ( ) const
noexcept

Get the process Id.

Definition at line 536 of file process.cpp.

◆ swap()

void CppCommon::Process::swap ( Process process)
noexcept

Swap two instances.

Definition at line 554 of file process.cpp.

◆ Wait()

int CppCommon::Process::Wait ( )

Wait the process to exit.

Will block.

Returns
Process exit result
Examples
system_process.cpp, and system_process_pipes.cpp.

Definition at line 541 of file process.cpp.

◆ WaitFor()

int CppCommon::Process::WaitFor ( const Timespan timespan)

Wait the process to exit for the given timespan.

Will block for the given timespan in the worst case.

Parameters
timespan- Timespan to wait for the process
Returns
Process exit result (std::numeric_limits<int>::min() in case of timeout)

Definition at line 542 of file process.cpp.

◆ WaitUntil()

int CppCommon::Process::WaitUntil ( const UtcTimestamp timestamp)
inline

Wait the process to exit until the given timestamp.

Will block until the given timestamp in the worst case.

Parameters
timestamp- Timestamp to stop wait for the process
Returns
Process exit result (std::numeric_limits<int>::min() in case of timeout)

Definition at line 79 of file process.h.

Friends And Related Function Documentation

◆ swap

void swap ( Process process1,
Process process2 
)
friend

Definition at line 21 of file process.inl.


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