]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/process/child.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / process / child.hpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 // Copyright (c) 2016 Klemens D. Morgenstern
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See accompanying
9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10
11 /**
12 * \file boost/process/child.hpp
13 *
14 * Defines a child process class.
15 */
16
17 #ifndef BOOST_PROCESS_CHILD_HPP
18 #define BOOST_PROCESS_CHILD_HPP
19
20 #include <boost/process/detail/config.hpp>
21 #include <boost/process/detail/child_decl.hpp>
22 #include <boost/process/detail/execute_impl.hpp>
23
24 #if defined(BOOST_POSIX_API)
25 #include <boost/process/posix.hpp>
26 #endif
27
28 namespace boost {
29
30 ///The main namespace of boost.process.
31 namespace process {
32
33 template<typename ...Args>
34 child::child(Args&&...args)
35 : child(::boost::process::detail::execute_impl(std::forward<Args>(args)...)) {}
36
37
38 ///Typedef for the type of an pid_t
39 typedef ::boost::process::detail::api::pid_t pid_t;
40
41 #if defined(BOOST_PROCESS_DOXYGEN)
42 /** The main class to hold a child process. It is simliar to [std::thread](http://en.cppreference.com/w/cpp/thread/thread),
43 * in that it has a join and detach function.
44 *
45 * @attention The destructor will call terminate on the process if not joined or detached without any warning.
46 *
47 */
48
49 class child
50 {
51 /** Type definition for the native process handle. */
52 typedef platform_specific native_handle_t;
53
54 /** Construct the child from a pid.
55 *
56 * @attention There is no guarantee that this will work. The process need the right access rights, which are very platform specific.
57 */
58 explicit child(pid_t & pid) : _child_handle(pid) {};
59
60 /** Move-Constructor.*/
61 child(child && lhs);
62
63 /** Construct a child from a property list and launch it
64 * The standard version is to create a subprocess, which will spawn the process.
65 */
66 template<typename ...Args>
67 explicit child(Args&&...args);
68
69 /** Construct an empty child. */
70 child() = default;
71
72 /** Move assign. */
73 child& operator=(child && lhs);
74
75 /** Detach the child, i.e. let it run after this handle dies. */
76 void detach();
77 /** Join the child. This just calls wait, but that way the naming is similar to std::thread */
78 void join();
79 /** Check if the child is joinable. */
80 bool joinable();
81
82 /** Destructor.
83 * @attention Will call terminate (without warning) when the child was neither joined nor detached.
84 */
85 ~child();
86
87 /** Get the native handle for the child process. */
88 native_handle_t native_handle() const;
89
90 /** Get the exit_code. The return value is without any meaning if the child wasn't waited for or if it was terminated. */
91 int exit_code() const;
92 /** Get the Process Identifier. */
93 pid_t id() const;
94
95 /** Check if the child process is running. */
96 bool running();
97 /** \overload void running() */
98 bool running(std::error_code & ec) noexcept;
99
100 /** Wait for the child process to exit. */
101 void wait();
102 /** \overload void wait() */
103 void wait(std::error_code & ec) noexcept;
104
105 /** Wait for the child process to exit for a period of time.
106 * \return True if child exited while waiting.
107 */
108 template< class Rep, class Period >
109 bool wait_for (const std::chrono::duration<Rep, Period>& rel_time);
110 /** \overload bool wait_for(const std::chrono::duration<Rep, Period>& rel_time) */
111 bool wait_for (const std::chrono::duration<Rep, Period>& rel_time, std::error_code & ec) noexcept;
112
113 /** Wait for the child process to exit until a point in time.
114 * \return True if child exited while waiting.*/
115 template< class Clock, class Duration >
116 bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time );
117 /** \overload bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time )*/
118 bool wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time, std::error_code & ec) noexcept;
119
120 /** Check if this handle holds a child process.
121 * @note That does not mean, that the process is still running. It only means, that the handle does or did exist.
122 */
123 bool valid() const;
124 /** Same as valid, for convenience. */
125 explicit operator bool() const;
126
127 /** Check if the the chlid process is in any process group. */
128 bool in_group() const;
129
130 /** \overload bool in_group() const */
131 bool in_group(std::error_code & ec) const noexcept;
132
133 /** Terminate the child process.
134 *
135 * This function will cause the child process to unconditionally and immediately exit.
136 * It is implement with [SIGKILL](http://pubs.opengroup.org/onlinepubs/009695399/functions/kill.html) on posix
137 * and [TerminateProcess](https://technet.microsoft.com/en-us/library/ms686714.aspx) on windows.
138 *
139 */
140 void terminate();
141
142 /** \overload void terminate() */
143 void terminate(std::error_code & ec) noexcept;
144 };
145
146 #endif
147
148 }}
149 #endif
150