17 #ifndef COM_BORA_SOFTWARE__BALAU_CONCURRENT__FORK 18 #define COM_BORA_SOFTWARE__BALAU_CONCURRENT__FORK 23 #include <boost/predef.h> 36 #pragma clang diagnostic push 37 #pragma ide diagnostic ignored "OCSimplifyInspection" 38 #pragma ide diagnostic ignored "OCDFAInspection" 40 #pragma clang diagnostic pop 55 public:
static int performFork(
const std::function<
int ()> &
function,
bool exitChild) {
58 const int pid = ::fork();
61 const int status =
function();
87 public:
static int performFork(
const std::function<
int ()> &
function) {
90 const int pid = ::fork();
139 exitStatus = rhs.exitStatus;
159 int options = WEXITED;
161 memset(&infop, 0,
sizeof(siginfo_t));
163 if (waitid(P_PID, (
unsigned int) pid, &infop, options) == -1) {
165 }
else if (infop.si_pid) {
191 int options = WEXITED | WNOHANG;
193 memset(&infop, 0,
sizeof(siginfo_t));
195 if (waitid(P_PID, (
unsigned int) pid, &infop, options) == -1) {
197 }
else if (infop.si_pid) {
198 switch (infop.si_code) {
222 std::vector<TerminationReport> reports;
224 int options = WEXITED | WNOHANG;
226 for (
int pid : pids) {
231 memset(&infop, 0,
sizeof(siginfo_t));
233 if (waitid(P_PID, (
unsigned int)
pid, &infop, options) == -1) {
235 }
else if (infop.si_pid) {
236 switch (infop.si_code) {
240 reports.emplace_back(pid, infop.si_code, infop.si_status);
269 int options = WEXITED | WNOHANG;
271 memset(&infop, 0,
sizeof(siginfo_t));
273 if (waitid(P_PID, (
unsigned int) pid, &infop, options) == -1) {
275 }
else if (infop.si_pid) {
276 switch (infop.si_code) {
296 #endif // COM_BORA_SOFTWARE__BALAU_CONCURRENT__FORK static TerminationReport terminateProcess(int pid)
Terminate the child process if it is running.
Definition: Fork.hpp:263
static bool forkSupported()
Determine whether forking is support on this platform.
Definition: Fork.hpp:35
static std::vector< TerminationReport > checkForTermination(const std::vector< int > &pids)
Check without blocking the supplied processes for termination.
Definition: Fork.hpp:221
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
static int performFork(const std::function< int()> &function, bool exitChild)
Perform a fork operator and run the supplied function for the child.
Definition: Fork.hpp:55
Convenience wrapper for forking processes.
Definition: Fork.hpp:31
int code
The signal code.
Definition: Fork.hpp:117
Balau exceptions for system utilities.
static TerminationReport waitOnProcess(int pid)
Wait on a process until the process terminates.
Definition: Fork.hpp:153
static int performFork(const std::function< int()> &function)
Perform a fork operator and run the supplied function for the child.
Definition: Fork.hpp:87
Concurrency control classes.
Definition: CyclicBarrier.hpp:26
A termination report, returned by wait methods.
Definition: Fork.hpp:108
Thrown when a fork call fails.
Definition: SystemExceptions.hpp:58
Assertion utilities for development purposes.
Thrown when a wait call fails.
Definition: SystemExceptions.hpp:70
static TerminationReport checkForTermination(int pid)
Check the process for termination without blocking.
Definition: Fork.hpp:185
int pid
The PID of the process.
Definition: Fork.hpp:112
int exitStatus
The exit status.
Definition: Fork.hpp:122
static void assertion(bool test, StringFunctionT function)
If the bug test assertion fails, abort after logging the message supplied by the function.
Definition: Assert.hpp:49