ark::process::Process

Defined in header “ark/process/process.hh”.


Allows you to construct and execute a process from within your code. You can control the lifetime of the process, along with managing standard output/error, and retrieve return codes.

Methods

  • Process(ProcessConfiguration config)
    Constructor. Initializes a new process with the given configuration.

  • Process(ProcessConfiguration config, std::string executable_code_bytes)
    Constructor. Initializes a new process with the given configuration. Reads the code to execute from the provided ’executable bytes’ rather than trying to launch an executable directly.

  • ~Process()
    Destructor. If you haven’t already called wait(), this will invoke wait() and wait for the process to exit (and may throw).

  • Process(const Process & other)
    Deleted copy/move operators.

  • Process & operator=(const Process & other)

  • Process(Process && other)

  • Process & operator=(Process && other)

  • bool exited()
    Returns true if the process has exited and cleaned up successfully. In other words, this is true if wait() has already returned true once.

  • bool wait(std::chrono::nanoseconds timeout)
    Waits for the process to exit. Returns true if the process has exited, or false otherwise. This will block for the given duration.

    You MUST call this to ensure the process exits.

  • void interrupt()
    Sends a SIGINT signal to the process, such as you might get when the process is interrupted (ie, via CTRL+C). The process can ignore this signal.

  • void terminate()
    Stops the current process, sending a terminate signal to it. You need to call wait() after to ensure it exits. Note that the process can ignore this signal.

  • void kill()
    Stops the calling process, sending a kill signal to it. You need to call wait() after to ensure it exits. This signal cannot be ignored and should immediately kill the process.

  • int return_code()
    Returns the ‘return code’ (or exit code) of the process. This is only safe to call once wait() has returned true.

  • int terminating_signal()
    Returns the terminating signal of the process, if any. This will be 0 if there was no terminating signal. This is only safe to call once wait() has returned true.

  • size_t read_output(void * destination, size_t maximum_size, std::chrono::nanoseconds timeout)
    Reads from the merged stdout/stderr stream. This will read some number of bytes from standard output into the given buffer. The number of bytes actually read are returned.

  • std::string read_output(std::chrono::nanoseconds timeout)
    Reads from the merged stdout/stderr stream, returning the result as a string. This just reads some number of bytes, there might be more output to read.

  • native_handle_type native_handle()
    Returns the descriptor used for output (the pipe), allowing you to wait on it as part of a poll set.