diff options
Diffstat (limited to 'base/process_util_posix.cc')
-rw-r--r-- | base/process_util_posix.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index dee917d..8e6781e 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -4,6 +4,7 @@ #include "base/process_util.h" +#include <errno.h> #include <signal.h> #include <sys/resource.h> #include <sys/time.h> @@ -96,6 +97,25 @@ void RaiseProcessToHighPriority() { // setpriority() or sched_getscheduler, but these all require extra rights. } +bool WaitForExitCode(ProcessHandle handle, int* exit_code) { + int status; + while (waitpid(handle, &status, 0) == -1) { + if (errno != EINTR) { + NOTREACHED(); + return false; + } + } + + if (WIFEXITED(status)) { + *exit_code = WEXITSTATUS(status); + return true; + } + + // If it didn't exit cleanly, it must have been signaled. + DCHECK(WIFSIGNALED(status)); + return false; +} + bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { // This POSIX version of this function only guarantees that we wait no less // than |wait_milliseconds| for the proces to exit. The child process may |