Get pid of recursive subprocesses

天大地大妈咪最大 提交于 2019-12-25 08:16:11

问题


Scenario: subprocess created a subprocess and so on, how can i get it's pid?

I used subprocess.popen to launch the first subprocess, for example word file, this word file generated a new subprocess, how can i get it's pid?


回答1:


Using psutil:

parent = psutil.Process(parent_pid)
children = parent.children()
# all child pids can be accessed using the pid attribute
child_pids = [p.pid for p in children]


来源:https://stackoverflow.com/questions/40509813/get-pid-of-recursive-subprocesses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!