aboutsummaryrefslogtreecommitdiff
path: root/butl/process.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-04-27 18:47:01 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2016-04-29 10:25:37 +0300
commit6cd172c32ebe79692e19433f49716e58c57c8677 (patch)
tree579995efe00d14c3f26d6921bf1f55162b629330 /butl/process.cxx
parenta08803f6675a77971884604c0b79ce5f75ea93bb (diff)
Rework process internals, add current_id()
Diffstat (limited to 'butl/process.cxx')
-rw-r--r--butl/process.cxx32
1 files changed, 22 insertions, 10 deletions
diff --git a/butl/process.cxx b/butl/process.cxx
index 4203735..f00f03a 100644
--- a/butl/process.cxx
+++ b/butl/process.cxx
@@ -5,7 +5,7 @@
#include <butl/process>
#ifndef _WIN32
-# include <unistd.h> // execvp, fork, dup2, pipe, chdir, *_FILENO
+# include <unistd.h> // execvp, fork, dup2, pipe, chdir, *_FILENO, getpid
# include <sys/wait.h> // waitpid
#else
# ifndef WIN32_LEAN_AND_MEAN
@@ -36,12 +36,12 @@ namespace butl
(err == -1 && pipe (in_efd) == -1))
throw process_error (errno, false);
- id = fork ();
+ handle = fork ();
- if (id == -1)
+ if (handle == -1)
throw process_error (errno, false);
- if (id == 0)
+ if (handle == 0)
{
// Child. If requested, close the write end of the pipe and duplicate
// the read end to stdin. Then close the original read end descriptor.
@@ -109,10 +109,10 @@ namespace butl
bool process::
wait ()
{
- if (id != 0)
+ if (handle != 0)
{
- int r (waitpid (id, &status, 0));
- id = 0; // We have tried.
+ int r (waitpid (handle, &status, 0));
+ handle = 0; // We have tried.
if (r == -1)
throw process_error (errno, false);
@@ -124,14 +124,14 @@ namespace butl
bool process::
try_wait (bool& s)
{
- if (id != 0)
+ if (handle != 0)
{
- int r (waitpid (id, &status, WNOHANG));
+ int r (waitpid (handle, &status, WNOHANG));
if (r == 0) // Not exited yet.
return false;
- id = 0; // We have tried.
+ handle = 0; // We have tried.
if (r == -1)
throw process_error (errno, false);
@@ -141,8 +141,20 @@ namespace butl
return true;
}
+ process::id_type process::
+ current_id ()
+ {
+ return getpid ();
+ }
+
#else // _WIN32
+ process::id_type process::
+ current_id ()
+ {
+ return GetCurrentProcessId ();
+ }
+
static void
print_error (char const* name)
{