Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python执行shell命令,如何获取shell命令生成的进程的进程ID_Python_Shell - Fatal编程技术网

Python执行shell命令,如何获取shell命令生成的进程的进程ID

Python执行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

我想使用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(...)
print(p.pid)