Home | Libraries | People | FAQ | More |
boost::process::child
// In header: <boost/process/child.hpp> class child { public: // construct/copy/destruct explicit child(pid_t &); child(child &&); template<typename... Args> explicit child(Args &&...); child() = default; child & operator=(child &&); ~child(); // private member functions void detach(); void join(); bool joinable(); native_handle_t native_handle() const; int exit_code() const; pid_t id() const; bool running(); bool running(std::error_code &) noexcept; void wait(); void wait(std::error_code &) noexcept; template<typename Rep, typename Period> bool wait_for(const std::chrono::duration< Rep, Period > &); bool wait_for(const std::chrono::duration< Rep, Period > &, std::error_code &) noexcept; template<typename Clock, typename Duration> bool wait_until(const std::chrono::time_point< Clock, Duration > &); bool wait_until(const std::chrono::time_point< Clock, Duration > &, std::error_code &) noexcept; bool valid() const; explicit operator bool() const; bool in_group() const; bool in_group(std::error_code &) const noexcept; void terminate(); void terminate(std::error_code &) noexcept; };
The main class to hold a child process. It is simliar to std::thread, in that it has a join and detach function.
Note | |
---|---|
The destructor will call terminate on the process if not joined or detached without any warning. |
child
public
construct/copy/destructexplicit child(pid_t & pid);
Construct the child from a pid.
Note | |
---|---|
There is no guarantee that this will work. The process need the right access rights, which are very platform specific. |
child(child && lhs);
Move-Constructor.
template<typename... Args> explicit child(Args &&... args);
Construct a child from a property list and launch it The standard version is to create a subprocess, which will spawn the process.
child() = default;
Construct an empty child.
child & operator=(child && lhs);
Move assign.
~child();
Destructor.
Note | |
---|---|
Will call terminate (without warning) when the child was neither joined nor detached. |
child
private member functionsvoid detach();
Detach the child, i.e. let it run after this handle dies.
void join();
Join the child. This just calls wait, but that way the naming is similar to std::thread
bool joinable();
Check if the child is joinable.
native_handle_t native_handle() const;
Get the native handle for the child process.
int exit_code() const;
Get the exit_code. The return value is without any meaning if the child wasn't waited for or if it was terminated.
pid_t id() const;
Get the Process Identifier.
bool running();
Check if the child process is running.
bool running(std::error_code & ec) noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void wait();
Wait for the child process to exit.
void wait(std::error_code & ec) noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename Rep, typename Period> bool wait_for(const std::chrono::duration< Rep, Period > & rel_time);
Wait for the child process to exit for a period of time.
Returns: |
True if child exited while waiting. |
bool wait_for(const std::chrono::duration< Rep, Period > & rel_time, std::error_code & ec) noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
template<typename Clock, typename Duration> bool wait_until(const std::chrono::time_point< Clock, Duration > & timeout_time);
Wait for the child process to exit until a point in time.
Returns: |
True if child exited while waiting. |
bool wait_until(const std::chrono::time_point< Clock, Duration > & timeout_time, std::error_code & ec) noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool valid() const;
Check if this handle holds a child process.
Note | |
---|---|
That does not mean, that the process is still running. It only means, that the handle does or did exist. |
explicit operator bool() const;
Same as valid, for convenience.
bool in_group() const;
Check if the the chlid process is in any process group.
bool in_group(std::error_code & ec) const noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void terminate();
Terminate the child process.
This function will cause the child process to unconditionally and immediately exit. It is implement with SIGKILL on posix and TerminateProcess on windows.
void terminate(std::error_code & ec) noexcept;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.