terminate.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_DETAIL_POSIX_TERMINATE_HPP
  10. #define BOOST_PROCESS_DETAIL_POSIX_TERMINATE_HPP
  11. #include <boost/process/detail/config.hpp>
  12. #include <boost/process/detail/posix/child_handle.hpp>
  13. #include <system_error>
  14. #include <signal.h>
  15. #include <sys/wait.h>
  16. namespace boost { namespace process { namespace detail { namespace posix {
  17. inline void terminate(const child_handle &p, std::error_code &ec) noexcept
  18. {
  19. if (::kill(p.pid, SIGKILL) == -1)
  20. ec = boost::process::detail::get_last_error();
  21. else
  22. ec.clear();
  23. int status;
  24. ::waitpid(p.pid, &status, WNOHANG); //just to clean it up
  25. }
  26. inline void terminate(const child_handle &p)
  27. {
  28. std::error_code ec;
  29. terminate(p, ec);
  30. boost::process::detail::throw_error(ec, "kill(2) failed");
  31. }
  32. }}}}
  33. #endif