• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
12  * \file boost/process/spawn.hpp
13  *
14  * Defines the spawn function.
15  */
16 
17 #ifndef BOOST_PROCESS_SPAWN_HPP
18 #define BOOST_PROCESS_SPAWN_HPP
19 
20 #include <boost/process/detail/config.hpp>
21 #include <boost/process/detail/child_decl.hpp>
22 #include <boost/process/detail/execute_impl.hpp>
23 #include <boost/process/detail/async_handler.hpp>
24 
25 #if defined(BOOST_POSIX_API)
26 #include <boost/process/posix.hpp>
27 #endif
28 
29 namespace boost {
30 
31 namespace process {
32 
33 namespace detail {
34 
35 }
36 
37 /** Launch a process and detach it. Returns no handle.
38 
39 This function starts a process and immediately detaches it. It thereby prevents the system from creating a zombie process,
40 but will also cause the system to be unable to wait for the child to exit.
41 
42 \note This will set `SIGCHLD` to `SIGIGN` on posix.
43 
44 \warning This function does not allow asynchronous operations, since it cannot wait for the end of the process.
45 It will fail to compile if a reference to `boost::asio::io_context` is passed.
46 
47  */
48 template<typename ...Args>
spawn(Args &&...args)49 inline void spawn(Args && ...args)
50 {
51     typedef typename ::boost::process::detail::has_async_handler<Args...>::type
52             has_async;
53 
54 
55     static_assert(
56             !has_async::value,
57             "Spawn cannot wait for exit, so async properties cannot be used");
58 
59     auto c = ::boost::process::detail::execute_impl(
60 #if defined(BOOST_POSIX_API)
61             ::boost::process::posix::sig.ign(),
62 #endif
63              std::forward<Args>(args)...);
64     c.detach();
65 }
66 
67 }}
68 #endif
69 
70