| Home | Libraries | People | FAQ | More

## 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;
      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
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
   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
   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.     bool running();

   Check if the child process is running.

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

9.     void wait();

   Wait for the child process to exit.

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

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

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

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

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

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

16.     explicit operator bool() const;

    Same as valid, for convenience.

17.     bool in_group() const;

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

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

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

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