[CRIU] [PATCH 05/11] pstree: add a function to check if a task is in pstree

Qiang Huang h.huangqiang at huawei.com
Thu Jan 17 03:09:31 EST 2013


Sometimes, when we parse some global info files, we can only care about
tasks which are taken into dump(such as file locks), which means their
pids are in the pstree.
So a function like this would be help.

Signed-off-by: Qiang Huang <h.huangqiang at huawei.com>
---
 include/pstree.h |    1 +
 pstree.c         |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/include/pstree.h b/include/pstree.h
index d13dacf..cefc750 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -58,6 +58,7 @@ extern bool restore_before_setsid(struct pstree_item *child);
 extern int prepare_pstree(void);
 
 extern int dump_pstree(struct pstree_item *root_item);
+extern bool pid_in_pstree(pid_t pid);
 
 struct task_entries;
 extern struct task_entries *task_entries;
diff --git a/pstree.c b/pstree.c
index 3ba645e..216f95d 100644
--- a/pstree.c
+++ b/pstree.c
@@ -455,3 +455,15 @@ bool restore_before_setsid(struct pstree_item *child)
 
 	return false;
 }
+
+bool pid_in_pstree(pid_t pid)
+{
+	struct pstree_item *item;
+
+	for_each_pstree_item(item) {
+		if (item->pid.real == pid)
+			return true;
+	}
+
+	return false;
+}
-- 
1.7.1




More information about the CRIU mailing list