terminate.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2006, 2007 Julio M. Merino Vidal
  2. // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
  3. // Copyright (c) 2009 Boris Schaeling
  4. // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
  5. // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_PROCESS_WINDOWS_TERMINATE_HPP
  10. #define BOOST_PROCESS_WINDOWS_TERMINATE_HPP
  11. #include <boost/process/detail/config.hpp>
  12. #include <system_error>
  13. #include <cstdlib>
  14. #include <boost/winapi/process.hpp>
  15. #include <boost/winapi/get_last_error.hpp>
  16. namespace boost { namespace process { namespace detail { namespace windows {
  17. struct child_handle;
  18. inline void terminate(child_handle &p, std::error_code &ec) noexcept
  19. {
  20. if (!::boost::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE))
  21. ec = boost::process::detail::get_last_error();
  22. else
  23. {
  24. ec.clear();
  25. ::boost::winapi::CloseHandle(p.proc_info.hProcess);
  26. p.proc_info.hProcess = ::boost::winapi::INVALID_HANDLE_VALUE_;
  27. }
  28. }
  29. inline void terminate(child_handle &p)
  30. {
  31. std::error_code ec;
  32. terminate(p, ec);
  33. boost::process::detail::throw_error(ec, "TerminateProcess() failed in terminate");
  34. }
  35. }}}}
  36. #endif