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 <sys/types.h>
13#include <sys/wait.h>
14
16#include <boost/system/error_code.hpp>
17
19{
20
21 template <class Process>
22 inline int
23 wait_for_exit(const Process& p)
24 {
25 pid_t ret;
26 int status;
27 do
28 {
29 ret = ::waitpid(p.pid, &status, 0);
30 } while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
31 if (ret == -1)
32 {
33 BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("waitpid(2) failed");
34 }
35 return status;
36 }
37
38 template <class Process>
39 inline int
40 wait_for_exit(const Process& p, boost::system::error_code& ec)
41 {
42 pid_t ret;
43 int status;
44 do
45 {
46 ret = ::waitpid(p.pid, &status, 0);
47 } while ((ret == -1 && errno == EINTR) || (ret != -1 && !WIFEXITED(status)));
48 if (ret == -1)
49 {
50 BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
51 }
52 else
53 {
54 ec.clear();
55 }
56 return status;
57 }
58
59} // namespace boost::process::posix
Defines various macros.
int wait_for_exit(const Process &p)