spawn.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // Copyright (c) 2016 Klemens D. Morgenstern
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. /**
  11. * \file boost/process/spawn.hpp
  12. *
  13. * Defines the spawn function.
  14. */
  15. #ifndef BOOST_PROCESS_SPAWN_HPP
  16. #define BOOST_PROCESS_SPAWN_HPP
  17. #include <boost/process/detail/config.hpp>
  18. #include <boost/process/detail/child_decl.hpp>
  19. #include <boost/process/detail/execute_impl.hpp>
  20. #include <boost/process/detail/async_handler.hpp>
  21. #if defined(BOOST_POSIX_API)
  22. #include <boost/process/posix.hpp>
  23. #endif
  24. namespace boost {
  25. namespace process {
  26. namespace detail {
  27. }
  28. /** Launch a process and detach it. Returns no handle.
  29. This function starts a process and immediately detaches it. It thereby prevents the system from creating a zombie process,
  30. but will also cause the system to be unable to wait for the child to exit.
  31. \note This will set `SIGCHLD` to `SIGIGN` on posix.
  32. \warning This function does not allow asynchronous operations, since it cannot wait for the end of the process.
  33. It will fail to compile if a reference to `boost::asio::io_context` is passed.
  34. */
  35. template<typename ...Args>
  36. inline void spawn(Args && ...args)
  37. {
  38. typedef typename ::boost::process::detail::has_async_handler<Args...>::type
  39. has_async;
  40. static_assert(
  41. !has_async::value,
  42. "Spawn cannot wait for exit, so async properties cannot be used");
  43. auto c = ::boost::process::detail::execute_impl(
  44. #if defined(BOOST_POSIX_API)
  45. ::boost::process::posix::sig.ign(),
  46. #endif
  47. std::forward<Args>(args)...);
  48. c.detach();
  49. }
  50. }}
  51. #endif