is_running.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (c) 2016 Klemens D. Morgenstern
  2. //
  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)
  5. #ifndef BOOST_PROCESS_WINDOWS_IS_RUNNING_HPP
  6. #define BOOST_PROCESS_WINDOWS_IS_RUNNING_HPP
  7. #include <boost/process/v1/detail/config.hpp>
  8. #include <boost/process/v1/detail/windows/child_handle.hpp>
  9. #include <system_error>
  10. #include <cstdlib>
  11. #include <boost/winapi/process.hpp>
  12. namespace boost { namespace process { BOOST_PROCESS_V1_INLINE namespace v1 { namespace detail { namespace windows {
  13. constexpr static ::boost::winapi::DWORD_ still_active = 259;
  14. struct child_handle;
  15. inline bool is_running(const child_handle &p, int & exit_code, std::error_code &ec) noexcept
  16. {
  17. ::boost::winapi::DWORD_ code;
  18. //single value, not needed in the winapi.
  19. if (!::boost::winapi::GetExitCodeProcess(p.process_handle(), &code))
  20. ec = ::boost::process::v1::detail::get_last_error();
  21. else
  22. ec.clear();
  23. if (code == still_active)
  24. return true;
  25. else
  26. {
  27. exit_code = code;
  28. return false;
  29. }
  30. }
  31. inline bool is_running(const child_handle &p, int & exit_code)
  32. {
  33. std::error_code ec;
  34. bool b = is_running(p, exit_code, ec);
  35. boost::process::v1::detail::throw_error(ec, "GetExitCodeProcess() failed in is_running");
  36. return b;
  37. }
  38. inline bool is_running(int code)
  39. {
  40. return code == still_active;
  41. }
  42. inline int eval_exit_status(int in ) {return in;}
  43. }}}}}
  44. #endif