You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/08/06 08:08:28 UTC
[02/13] git commit: Added os::process and os::children that uses a
Process list.
Added os::process and os::children that uses a Process list.
Review: https://reviews.apache.org/r/12428
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3903b00b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3903b00b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3903b00b
Branch: refs/heads/master
Commit: 3903b00b7a95860ecb2dd9643832f18fa60c0799
Parents: f506bb1
Author: Benjamin Hindman <be...@twitter.com>
Authored: Sun Jun 23 17:34:21 2013 -0400
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Mon Aug 5 23:08:03 2013 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/os.hpp | 34 ++++++++++++++++----
1 file changed, 28 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3903b00b/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 f159c79..7e85d62 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -1023,14 +1023,24 @@ inline Try<std::list<Process> > processes()
}
-inline Try<std::set<pid_t> > children(pid_t pid, bool recursive = true)
+inline Option<Process> process(
+ pid_t pid,
+ const std::list<Process>& processes)
{
- const Try<std::list<Process> >& processes = os::processes();
-
- if (processes.isError()) {
- return Error(processes.error());
+ foreach (const Process& process, processes) {
+ if (process.pid == pid) {
+ return process;
+ }
}
+ return None();
+}
+
+inline std::set<pid_t> children(
+ pid_t pid,
+ const std::list<Process>& processes,
+ bool recursive = true)
+{
// Perform a breadth first search for descendants.
std::set<pid_t> descendants;
std::queue<pid_t> parents;
@@ -1041,7 +1051,7 @@ inline Try<std::set<pid_t> > children(pid_t pid, bool recursive = true)
parents.pop();
// Search for children of parent.
- foreach (const Process& process, processes.get()) {
+ foreach (const Process& process, processes) {
if (process.parent == parent) {
// Have we seen this child yet?
if (descendants.insert(process.pid).second) {
@@ -1055,6 +1065,18 @@ inline Try<std::set<pid_t> > children(pid_t pid, bool recursive = true)
}
+inline Try<std::set<pid_t> > children(pid_t pid, bool recursive = true)
+{
+ const Try<std::list<Process> >& processes = os::processes();
+
+ if (processes.isError()) {
+ return Error(processes.error());
+ }
+
+ return children(pid, processes.get(), recursive);
+}
+
+
// Overload of os::pids for filtering by groups and sessions.
// A group / session id of 0 will fitler on the group / session ID
// of the calling process.