【发布时间】:2023-04-02 03:50:01
【问题描述】:
我想获取给定 PID 的所有直系子级的列表。我可以使用/proc,但/proc/<PID>/task/<PID>/children 并不精确,可能会返回不准确的结果(see section 3.7 here)。我想要一个更可靠的方法来做到这一点。
我不希望在 shell 命令周围使用包装器。
【问题讨论】:
标签: python node.js linux ubuntu process
我想获取给定 PID 的所有直系子级的列表。我可以使用/proc,但/proc/<PID>/task/<PID>/children 并不精确,可能会返回不准确的结果(see section 3.7 here)。我想要一个更可靠的方法来做到这一点。
我不希望在 shell 命令周围使用包装器。
【问题讨论】:
标签: python node.js linux ubuntu process
为什么不使用 psutils?
这是一个我杀死所有孩子的例子。
def infanticide(pid):
try:
parent = psutil.Process(pid)
except psutil.NoSuchProcess:
return
children = parent.children(recursive=True)
for p in children:
os.kill(p.pid, signal.SIGKILL)
【讨论】: