问题
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