Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit b9ab49fc70.
PrevUpHomeNext

Class child

boost::process::child

Synopsis

// 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;
  int native_exit_code() 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;
};

Description

The main class to hold a child process. It is simliar to std::thread, in that it has a join and detach function.

[Note] Note

The destructor will call terminate on the process if not joined or detached without any warning.

child public construct/copy/destruct

  1. explicit child(pid_t & pid);

    Construct the child from a pid.

    [Note] Note

    There is no guarantee that this will work. The process need the right access rights, which are very platform specific.

  2. child(child && lhs);

    Move-Constructor.

  3. 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.

  4. child() = default;

    Construct an empty child.

  5. child & operator=(child && lhs);

    Move assign.

  6. ~child();

    Destructor.

    [Note] Note

    Will call terminate (without warning) when the child was neither joined nor detached.

child private member functions

  1. void detach();

    Detach the child, i.e. let it run after this handle dies.

  2. void join();

    Join the child. This just calls wait, but that way the naming is similar to std::thread

  3. bool joinable();

    Check if the child is joinable.

  4. native_handle_t native_handle() const;

    Get the native handle for the child process.

  5. 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.

  6. pid_t id() const;

    Get the Process Identifier.

  7. int native_exit_code() const;

    Get the native, uninterpreted exit code. The return value is without any meaning if the child wasn't waited for or if it was terminated.

  8. bool running();

    Check if the child process is running.

  9. 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.

  10. void wait();

    Wait for the child process to exit.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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.

  16. bool valid() const;

    Check if this handle holds a child process.

    [Note] Note

    That does not mean, that the process is still running. It only means, that the handle does or did exist.

  17. explicit operator bool() const;

    Same as valid, for convenience.

  18. bool in_group() const;

    Check if the the chlid process is in any process group.

  19. 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.

  20. 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.

  21. 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.


PrevUpHomeNext