You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2013/06/20 05:30:20 UTC

[4/6] git commit: Added a zombie bit to os::Process, improved os::alive to handle zombie processes.

Added a zombie bit to os::Process, improved os::alive to handle
zombie processes.

Review: https://reviews.apache.org/r/11848


Project: http://git-wip-us.apache.org/repos/asf/incubator-mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mesos/commit/a79526fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mesos/tree/a79526fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mesos/diff/a79526fb

Branch: refs/heads/master
Commit: a79526fb3104610038c3f7abc78348d8d4516e4e
Parents: 5faf700
Author: Benjamin Mahler <bm...@twitter.com>
Authored: Wed Jun 12 12:04:00 2013 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Wed Jun 19 20:29:37 2013 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 24 ++++++++++++++------
 .../3rdparty/stout/include/stout/os/linux.hpp   |  3 ++-
 .../3rdparty/stout/include/stout/os/osx.hpp     |  6 +++--
 .../3rdparty/stout/include/stout/os/process.hpp |  7 ++++--
 4 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/a79526fb/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 47e877c..af47e18 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -1111,17 +1111,27 @@ inline Try<std::set<pid_t> > pids(Option<pid_t> group, Option<pid_t> session)
 
 inline Try<bool> alive(pid_t pid)
 {
-  CHECK(pid > 0);
-
-  if (::kill(pid, 0) == 0) {
-    return true;
+  if (pid <= 0) {
+    return Error("Invalid pid");
   }
 
-  if (errno == ESRCH) {
-    return false;
+  const Try<os::Process>& process = os::process(pid);
+
+  // When we can't get the process information, fall back
+  // to using kill.
+  if (process.isError()) {
+    if (::kill(pid, 0) == 0) {
+      return true;
+    }
+
+    if (errno == ESRCH) {
+      return false;
+    }
+
+    return Try<bool>::error(strerror(errno));
   }
 
-  return Try<bool>::error(strerror(errno));
+  return !process.get().zombie;
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/a79526fb/3rdparty/libprocess/3rdparty/stout/include/stout/os/linux.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/linux.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/linux.hpp
index 6fb9256..632f95f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/linux.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/linux.hpp
@@ -49,7 +49,8 @@ inline Try<Process> process(pid_t pid)
                  Bytes(status.get().rss * pageSize),
                  Duration::create(status.get().utime / (double) ticks).get(),
                  Duration::create(status.get().stime / (double) ticks).get(),
-                 status.get().comm);
+                 status.get().comm,
+                 status.get().state == 'Z');
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/a79526fb/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp
index c27e7a2..f2d241a 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/osx.hpp
@@ -52,7 +52,8 @@ inline Try<Process> process(pid_t pid)
                    Bytes(0),
                    Nanoseconds(-1),
                    Nanoseconds(-1),
-                   process.kp_proc.p_comm);
+                   process.kp_proc.p_comm,
+                   process.kp_proc.p_stat & SZOMB);
   } else {
     return Process(process.kp_proc.p_pid,
                    process.kp_eproc.e_ppid,
@@ -61,7 +62,8 @@ inline Try<Process> process(pid_t pid)
                    Bytes(task.pti_resident_size),
                    Nanoseconds(task.pti_total_user),
                    Nanoseconds(task.pti_total_system),
-                   process.kp_proc.p_comm);
+                   process.kp_proc.p_comm,
+                   process.kp_proc.p_stat & SZOMB);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/a79526fb/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp
index a88118a..806949b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp
@@ -19,7 +19,8 @@ struct Process
           const Bytes& _rss,
           const Duration& _utime,
           const Duration& _stime,
-          const std::string& _command)
+          const std::string& _command,
+          bool _zombie)
     : pid(_pid),
       parent(_parent),
       group(_group),
@@ -27,7 +28,8 @@ struct Process
       rss(_rss),
       utime(_utime),
       stime(_stime),
-      command(_command) {}
+      command(_command),
+      zombie(_zombie) {}
 
   const pid_t pid;
   const pid_t parent;
@@ -37,6 +39,7 @@ struct Process
   const Duration utime;
   const Duration stime;
   const std::string command;
+  const bool zombie;
 
   // TODO(bmahler): Add additional data as needed.