Get pid of recursive subprocesses

2019-09-11 04:57发布

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条回答
相关推荐>>
2楼-- · 2019-09-11 05:14

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]
查看更多
登录 后发表回答