提交 06b1317c 编写于 作者: A Amador Pahim

avocado.utils.process: recursive get_children_pids()

The current implementation of get_children_pids() returns only the first
level of subprocesses.

This patch adds the option to recursively create the list of
subprocesses from all sub-levels.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 4209a61f
......@@ -203,13 +203,28 @@ def process_in_ptree_is_defunct(ppid):
return defunct
def get_children_pids(ppid):
def get_children_pids(ppid, recursive=False):
"""
Get all PIDs of children/threads of parent ppid
param ppid: parent PID
param recursive: True to return all levels of subprocesses
return: list of PIDs of all children/threads of ppid
"""
return system_output("ps -L --ppid=%d -o lwp" % ppid, verbose=False).split('\n')[1:]
cmd = "ps -L --ppid=%d -o lwp"
# Getting first level of subprocesses
children = system_output(cmd % ppid, verbose=False).split('\n')[1:]
if not recursive:
return children
# Recursion to get all levels of subprocesses
for child in children:
children.extend(system_output(cmd % int(child),
verbose=False,
ignore_status=True).split('\n')[1:])
return children
def binary_from_shell_cmd(cmd):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册