os.system返回退出代码。它不提供子进程的pid。
使用
subprocess模块。
import subprocessimport timeargument = '...'proc = subprocess.Popen(['python', 'bar.py', argument], shell=True)time.sleep(3) # <-- There's no time.wait, but time.sleep.pid = proc.pid # <--- access `pid` attribute to get the pid of the child process.
要终止该过程,可以使用
terminate方法或
kill。(无需使用外部
kill程序)
proc.terminate()



