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/posix/child_handle.hpp>
10 #include <system_error>
13 namespace boost { namespace process { namespace detail { namespace posix {
21 typedef pid_t handle_t;
22 handle_t handle() const { return grp; }
24 explicit group_handle(handle_t h) :
30 group_handle() = default;
32 ~group_handle() = default;
33 group_handle(const group_handle & c) = delete;
34 group_handle(group_handle && c) : grp(c.grp)
38 group_handle &operator=(const group_handle & c) = delete;
39 group_handle &operator=(group_handle && c)
47 void add(handle_t proc)
49 if (::setpgid(proc, grp))
52 void add(handle_t proc, std::error_code & ec) noexcept
54 if (::setpgid(proc, grp))
55 ec = get_last_error();
58 bool has(handle_t proc)
60 return ::getpgid(proc) == grp;
62 bool has(handle_t proc, std::error_code & ec) noexcept
64 return ::getpgid(proc) == grp;
75 inline void terminate(group_handle &p)
77 if (::killpg(p.grp, SIGKILL) == -1)
78 boost::process::detail::throw_last_error("killpg(2) failed");
82 inline void terminate(group_handle &p, std::error_code &ec) noexcept
84 if (::killpg(p.grp, SIGKILL) == -1)
85 ec = boost::process::detail::get_last_error();
93 inline bool in_group()
103 #endif /* BOOST_PROCESS_DETAIL_WINDOWS_GROUP_HPP_ */