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
10 #ifndef BOOST_PROCESS_WINDOWS_TERMINATE_HPP
11 #define BOOST_PROCESS_WINDOWS_TERMINATE_HPP
12
13 #include <boost/process/detail/config.hpp>
14 #include <system_error>
15 #include <cstdlib>
16 #include <boost/winapi/process.hpp>
17 #include <boost/winapi/get_last_error.hpp>
18
19 namespace boost { namespace process { namespace detail { namespace windows {
20
21 struct child_handle;
22
terminate(child_handle & p,std::error_code & ec)23 inline void terminate(child_handle &p, std::error_code &ec) noexcept
24 {
25 if (!::boost::winapi::TerminateProcess(p.process_handle(), EXIT_FAILURE))
26 ec = boost::process::detail::get_last_error();
27 else
28 {
29 ec.clear();
30 ::boost::winapi::CloseHandle(p.proc_info.hProcess);
31 p.proc_info.hProcess = ::boost::winapi::INVALID_HANDLE_VALUE_;
32 }
33 }
34
terminate(child_handle & p)35 inline void terminate(child_handle &p)
36 {
37 std::error_code ec;
38 terminate(p, ec);
39 boost::process::detail::throw_error(ec, "TerminateProcess() failed in terminate");
40 }
41
42 }}}}
43
44 #endif
45