SPH
Public Member Functions | List of all members
Process Class Reference

Holds a handle to a created process. More...

#include <Process.h>

Public Member Functions

 Process ()=default
 Creates a null process handle. More...
 
 Process (const Path &path, Array< std::string > &&args)
 Creates a process by running given executable file. More...
 
void wait ()
 Blocks the calling thread until the managed process exits. The function may block indefinitely. More...
 
void waitFor (const uint64_t duration)
 Blocks the calling thread until the managed process exits or for specified duration. More...
 
void waitUntil (const Function< bool()> &condition, const uint64_t checkEvery=100)
 Blocks the calling thread until the managed process exits or until given condition is met. More...
 

Detailed Description

Holds a handle to a created process.

The class allows to start, manage and kill a process. Note that the calling thread does not wait until the created process exits, unless function wait (waitFor, waitUntil) is executed. In particular, the process is not blocked in the destructor.

Definition at line 19 of file Process.h.

Constructor & Destructor Documentation

◆ Process() [1/2]

Process::Process ( )
default

Creates a null process handle.

◆ Process() [2/2]

Process::Process ( const Path path,
Array< std::string > &&  args 
)

Creates a process by running given executable file.

Parameters
pathPath to the executable. The file must exist.
argsArguments passes to the executable. Can be an empty array.
Exceptions
Exceptionif the file does not exist or the process fails to start.
Note
Uses Array instead of ArrayView to easily pass brace-initialized list.
Todo:
hopefully c_str doesn't return pointer to some temporary stuff ...

Definition at line 21 of file Process.cpp.

Member Function Documentation

◆ wait()

void Process::wait ( )

Blocks the calling thread until the managed process exits. The function may block indefinitely.

Definition at line 50 of file Process.cpp.

◆ waitFor()

void Process::waitFor ( const uint64_t  duration)

Blocks the calling thread until the managed process exits or for specified duration.

Parameters
durationMaximum wait duration in milliseconds.

◆ waitUntil()

void Process::waitUntil ( const Function< bool()> &  condition,
const uint64_t  checkEvery = 100 
)

Blocks the calling thread until the managed process exits or until given condition is met.

Parameters
conditionFunction returning true if the wait should be interrupted.
checkEveryPeriod of condition checking in milliseconds

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