wait_for_exit.hpp
Go to the documentation of this file.
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 #pragma once
11 
12 #include <boost/process/config.hpp>
13 #include <boost/system/error_code.hpp>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 
17 namespace boost::process::posix
18 {
19 
20  template <class Process>
21  inline int wait_for_exit(const Process& p)
22  {
23  pid_t ret;
24  int status;
25  do
26  {
27  ret = ::waitpid(p.pid, &status, 0);
28  }
29  while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
30  if (ret == -1)
31  {
32  BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("waitpid(2) failed");
33  }
34  return status;
35  }
36 
37  template <class Process>
38  inline int wait_for_exit(const Process& p, boost::system::error_code& ec)
39  {
40  pid_t ret;
41  int status;
42  do
43  {
44  ret = ::waitpid(p.pid, &status, 0);
45  }
46  while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
47  if (ret == -1)
48  {
49  BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
50  }
51  else
52  {
53  ec.clear();
54  }
55  return status;
56  }
57 
58 }
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:21
config.hpp
boost::process::posix::wait_for_exit
int wait_for_exit(const Process &p)
Definition: wait_for_exit.hpp:21
armarx::status
status
Definition: FiniteStateMachine.h:259
boost::process::posix
Definition: child.hpp:14