diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-25 12:48:15 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-25 12:48:15 +0200 |
commit | 44c0fc2820bb13018b200d3ec990c30cdd2a08cd (patch) | |
tree | 99445eac0ab0c0d10bcaf6b35020db0788f43e25 /butl/process.cxx | |
parent | efd154a6af61e80be1b0c46642cefd73cc83d7ed (diff) |
Add process::try_wait() for non-blocking wait
Diffstat (limited to 'butl/process.cxx')
-rw-r--r-- | butl/process.cxx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/butl/process.cxx b/butl/process.cxx index 66a831e..bd13392 100644 --- a/butl/process.cxx +++ b/butl/process.cxx @@ -121,6 +121,26 @@ namespace butl return WIFEXITED (status) && WEXITSTATUS (status) == 0; } + bool process:: + try_wait (bool& s) + { + if (id != 0) + { + int r (waitpid (id, &status, WNOHANG)); + + if (r == 0) // Not exited yet. + return false; + + id = 0; // We have tried. + + if (r == -1) + throw process_error (errno, false); + } + + s = WIFEXITED (status) && WEXITSTATUS (status) == 0; + return true; + } + #else // _WIN32 static void |