我有这个:
def get_process():
pids = []
process = None
for i in os.listdir('/proc'):
if i.isdigit():
pids.append(i)
for pid in pids:
proc = open(os.path.join('/proc', pid, 'cmdline'), 'r').readline()
if proc == "Something":
process = pid
return process
def is_running(pid):
return os.path.exists("/proc/%s" % str(pid))
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
process = get_process()
if process == None:
#do something
else:
#Wait until the process end
while is_running(process):
pass
Run Code Online (Sandbox Code Playgroud)
我认为这不是等待进程终止的最佳方式,必须有一些函数等待或者什么,但我找不到它.
免责声明:该流程不是子流程