Python执行shell命令,如何获取shell命令生成的进程的进程ID
我想使用python来执行shell命令,如何获取由shell命令生成的进程的进程IDPython执行shell命令,如何获取shell命令生成的进程的进程ID,python,shell,Python,Shell,我想使用python来执行shell命令,如何获取由shell命令生成的进程的进程ID 导入子流程 subprocess.Popen(['{}'.format(self.executor),'-c',{}'.format(config),stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True) 此shell命令执行的进程本身不退出,我需要运行10分钟才能终止它,如何获取进程的id?您必须存储对象Popen返回,然后使用其pid属性: p
导入子流程
subprocess.Popen(['{}'.format(self.executor),'-c',{}'.format(config),stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
此shell命令执行的进程本身不退出,我需要运行10分钟才能终止它,如何获取进程的id?您必须存储对象
Popen
返回,然后使用其pid
属性:
p = subprocess.Popen(...)
print(p.pid)