is_running.hpp 1.4 KB

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