...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::process::v2::basic_process — A class managing a subprocess.
// In header: <boost/process/v2/process.hpp> template<typename Executor = boost::asio::any_io_executor> struct basic_process { // types typedef Executor executor_type; // The executor of the process. typedef basic_process_handle< executor_type > handle_type; // The non-closing handle type. typedef typename handle_type::native_handle_type native_handle_type; // Provides access to underlying operating system facilities. // member classes/structs/unions struct async_wait_op_ { // public member functions template<typename Self> void operator()(Self &&); template<typename Self> void operator()(Self &&, error_code, native_exit_code_type); // public data members basic_process_handle< Executor > & handle; native_exit_code_type & res; }; // Rebinds the process_handle to another executor. template<typename Executor1> struct rebind_executor { // types typedef basic_process< Executor1 > other; // The socket type when rebound to the specified executor. }; // construct/copy/destruct basic_process() = default; basic_process(const basic_process &) = delete; basic_process(basic_process &&) = default; template<typename Executor1> basic_process(basic_process< Executor1 > &&); template<typename ... Inits> explicit basic_process(executor_type, const filesystem::path &, std::initializer_list< string_view >, Inits &&...); template<typename ... Inits> explicit basic_process(executor_type, const filesystem::path &, std::initializer_list< wstring_view >, Inits &&...); template<typename Args, typename ... Inits> explicit basic_process(executor_type, const filesystem::path &, Args &&, Inits &&...); template<typename ExecutionContext, typename ... Inits> explicit basic_process(ExecutionContext &, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, const filesystem::path & >::type, std::initializer_list< string_view >, Inits &&...); template<typename ExecutionContext, typename Args, typename ... Inits> explicit basic_process(ExecutionContext &, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, const filesystem::path & >::type, Args &&, Inits &&...); explicit basic_process(executor_type, pid_type); explicit basic_process(executor_type, pid_type, native_handle_type); explicit basic_process(executor_type); template<typename ExecutionContext> explicit basic_process(ExecutionContext &, pid_type, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr); template<typename ExecutionContext> explicit basic_process(ExecutionContext &, pid_type, native_handle_type, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr); template<typename ExecutionContext> explicit basic_process(ExecutionContext &, typename std::enable_if< is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr); basic_process & operator=(const basic_process &) = delete; basic_process & operator=(basic_process &&) = default; ~basic_process(); // public member functions executor_type get_executor(); handle_type & handle(); const handle_type & handle() const; void interrupt(); void interrupt(error_code &); void request_exit(); void request_exit(error_code &); void suspend(error_code &); void suspend(); void resume(error_code &); void resume(); void terminate(); void terminate(error_code &); int wait(); int wait(error_code &); handle_type detach(); native_handle_type native_handle(); int exit_code() const; pid_type id() const; native_exit_code_type native_exit_code() const; bool running(); bool running(error_code &) noexcept; bool is_open() const; template<Token WaitHandler DEFAULT_TYPE> async_wait(WaitHandler &&handler ); };
basic_process
public
construct/copy/destructbasic_process() = default;
An empty process is similar to a default constructed thread. It holds an empty handle and is a place holder for a process that is to be launched later.
basic_process(const basic_process &) = delete;
basic_process(basic_process && lhs) = default;Move construct the process. It will be detached from
lhs
. template<typename Executor1> basic_process(basic_process< Executor1 > && lhs);Move construct and rebind the executor.
template<typename ... Inits> explicit basic_process(executor_type executor, const filesystem::path & exe, std::initializer_list< string_view > args, Inits &&... inits);Construct a child from a property list and launch it using the default launcher..
template<typename ... Inits> explicit basic_process(executor_type executor, const filesystem::path & exe, std::initializer_list< wstring_view > args, Inits &&... inits);Construct a child from a property list and launch it using the default launcher..
template<typename Args, typename ... Inits> explicit basic_process(executor_type executor, const filesystem::path & exe, Args && args, Inits &&... inits);Construct a child from a property list and launch it using the default launcher..
template<typename ExecutionContext, typename ... Inits> explicit basic_process(ExecutionContext & context, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, const filesystem::path & >::type exe, std::initializer_list< string_view > args, Inits &&... inits);Construct a child from a property list and launch it using the default launcher..
template<typename ExecutionContext, typename Args, typename ... Inits> explicit basic_process(ExecutionContext & context, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, const filesystem::path & >::type exe, Args && args, Inits &&... inits);Construct a child from a property list and launch it using the default launcher.
explicit basic_process(executor_type exec, pid_type pid);Attach to an existing process.
explicit basic_process(executor_type exec, pid_type pid, native_handle_type native_handle);Attach to an existing process and the internal handle.
explicit basic_process(executor_type exec);Create an invalid handle.
template<typename ExecutionContext> explicit basic_process(ExecutionContext & context, pid_type pid, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr);Attach to an existing process.
template<typename ExecutionContext> explicit basic_process(ExecutionContext & context, pid_type pid, native_handle_type native_handle, typename std::enable_if< std::is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr);Attach to an existing process and the internal handle.
template<typename ExecutionContext> explicit basic_process(ExecutionContext & context, typename std::enable_if< is_convertible< ExecutionContext &, boost::asio::execution_context & >::value, void * >::type = nullptr);Create an invalid handle.
basic_process & operator=(const basic_process &) = delete;
basic_process & operator=(basic_process && lhs) = default;Move assign a process. It will be detached from
lhs
. ~basic_process();Destruct the handle and terminate the process if it wasn't detached.
basic_process
public member functionsexecutor_type get_executor();Get the executor of the process.
handle_type & handle();Get the underlying non-closing handle.
const handle_type & handle() const;Get the underlying non-closing handle.
void interrupt();Sends the process a signal to ask for an interrupt, which the process may interpret as a shutdown.
Maybe be ignored by the subprocess.
void interrupt(error_code & ec);Throwing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void request_exit();Throwing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void request_exit(error_code & ec);Sends the process a signal to ask for a graceful shutdown. Maybe be ignored by the subprocess.
void suspend(error_code & ec);Send the process a signal requesting it to stop. This may rely on undocumented functions.
void suspend();Send the process a signal requesting it to stop. This may rely on undocumented functions.
void resume(error_code & ec);Send the process a signal requesting it to resume. This may rely on undocumented functions.
void resume();Send the process a signal requesting it to resume. This may rely on undocumented functions.
void terminate();Throwing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void terminate(error_code & ec);Unconditionally terminates the process and stores the exit code in exit_status.
int wait();Throwing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int wait(error_code & ec);Waits for the process to exit, store the exit code internally and return it.
handle_type detach();Detach the process.
native_handle_type native_handle();
int exit_code() const;
pid_type id() const;Get the id of the process;.
native_exit_code_type native_exit_code() const;The native handle of the process.
This might be undefined on posix systems that only support signals
bool running();Checks if the current process is running.
If it has already completed the exit code will be stored internally and can be obtained by calling `exit_code.
bool running(error_code & ec) noexcept;Throwing.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool is_open() const;Check if the process is referring to an existing process.
Note that this might be a process that already exited.
template<Token WaitHandler DEFAULT_TYPE> async_wait(WaitHandler &&handler DEFAULT);Asynchronously wait for the process to exit and deliver the portable exit-code in the completion handler.