Skip to content

Engine → Core → process.h

process

Syntax

class CONJURE_API process

Constructors

AccessSignatureDescription
publicprocess();
publicprocess( process &&other) noexcept;

Important

Copy constructor and assignment has been deleted.

Destructors

AccessSignatureDescription
public~process();

Variables

AccessNameTypeDefaultDescription
publicKILLED_EXIT_CODEstatic constexpr i32-1Exit code reported for a child killed by kill() or by the timeout, and for a child whose exit status was lost (POSIX: SIGCHLD ignored by the host, or the child reaped elsewhere), so a lost status never reads as success.
publicMAX_TIMEOUT_SECONDSstatic constexpr f641.0e9Largest timeout honoured (about 31 years); larger finite values are clamped to it.
privatemStatestd::unique_ptr<state>{}

Functions

Public

is_running

[[nodiscard]] bool is_running() const noexcept;

True while the child has not exited and wait() has not been called.

kill

void kill() noexcept;

Kills the child and every process it spawned, including descendants that outlived the child itself. No-op once wait() returned. wait() still has to be called to collect the result.

process_id

[[nodiscard]] u32 process_id() const noexcept;

The operating system's identifier of the child, 0 when not started.

read_error

usize read_error(
    std::string &out);

Appends the standard error captured since the previous call and returns the number of bytes appended. Never blocks.

read_output

usize read_output(
    std::string &out);

Appends the standard output captured since the previous call and returns the number of bytes appended. Never blocks.

run

[[nodiscard]] static result<process_result> run(
    const process_desc &desc);

Starts the child and blocks until it exits or the timeout kills it. Fails with INVALID_ARGUMENT for an inconsistent description, NOT_FOUND when the executable or working directory does not exist, PERMISSION_DENIED or BACKEND_FAILURE when the operating system refuses to start it. A non-zero exit code is not an error.

start

[[nodiscard]] static result<process> start(
    const process_desc &desc);

Starts the child and returns immediately. Same failures as run().

wait

[[nodiscard]] result<process_result> wait();

Blocks until the child exits and its captured output is drained (killing the whole tree when the description's timeout elapses first), then returns its exit code and the output not yet consumed by read_output() / read_error(). Without a timeout a descendant that inherited the output pipe delays the return until it closes it. Fails with INVALID_STATE when the process was never started or wait() was already called.

Operator Overloads

Public

operator=

process &operator=(
    process &&other) noexcept;