1 // Copyright (c) 2106 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_IS_RUNNING_HPP
7 #define BOOST_PROCESS_DETAIL_POSIX_IS_RUNNING_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 {
17 constexpr int still_active = 0x7F;
18 static_assert(!WIFEXITED(still_active), "Internal Error");
20 inline bool is_running(const child_handle &p, int & exit_code)
23 auto ret = ::waitpid(p.pid, &status, WNOHANG|WUNTRACED);
27 if (errno != ECHILD) //because it no child is running, than this one isn't either, obviously.
28 ::boost::process::detail::throw_last_error("is_running error");
36 if (WIFEXITED(status))
42 inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept
45 auto ret = ::waitpid(p.pid, &status, WNOHANG|WUNTRACED);
49 if (errno != ECHILD) //because it no child is running, than this one isn't either, obviously.
50 ec = ::boost::process::detail::get_last_error();
59 if (WIFEXITED(status))
66 inline bool is_running(int code)
68 return !WIFEXITED(code);
71 inline int eval_exit_status(int code)
73 return WEXITSTATUS(code);