1 // Copyright (c) 2016 Klemens D. Morgenstern
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_PROCESS_DETAIL_POSIX_GROUP_HPP_
7 #define BOOST_PROCESS_DETAIL_POSIX_GROUP_HPP_
9 #include <boost/process/detail/config.hpp>
10 #include <boost/process/detail/posix/child_handle.hpp>
11 #include <system_error>
14 namespace boost { namespace process { namespace detail { namespace posix {
20 typedef pid_t handle_t;
21 handle_t handle() const { return grp; }
23 explicit group_handle(handle_t h) :
28 group_handle() = default;
30 ~group_handle() = default;
31 group_handle(const group_handle & c) = delete;
32 group_handle(group_handle && c) : grp(c.grp)
36 group_handle &operator=(const group_handle & c) = delete;
37 group_handle &operator=(group_handle && c)
44 void add(handle_t proc)
46 if (::setpgid(proc, grp))
49 void add(handle_t proc, std::error_code & ec) noexcept
51 if (::setpgid(proc, grp))
52 ec = get_last_error();
55 bool has(handle_t proc)
57 return ::getpgid(proc) == grp;
59 bool has(handle_t proc, std::error_code & ec) noexcept
61 return ::getpgid(proc) == grp;
70 inline void terminate(group_handle &p, std::error_code &ec) noexcept
72 if (::killpg(p.grp, SIGKILL) == -1)
73 ec = boost::process::detail::get_last_error();
80 inline void terminate(group_handle &p)
84 boost::process::detail::throw_error(ec, "killpg(2) failed in terminate");
87 inline bool in_group()
94 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */