Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.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
如果正在运行的命令是setsid,如何终止以shell=True启动的Python子进程_Python_Linux_Subprocess_Kill Process - Fatal编程技术网

如果正在运行的命令是setsid,如何终止以shell=True启动的Python子进程

如果正在运行的命令是setsid,如何终止以shell=True启动的Python子进程,python,linux,subprocess,kill-process,Python,Linux,Subprocess,Kill Process,我使用以下命令启动Python子流程: p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, start_new_session=True) 根据,start\u new\u session=True(等同于preexec\u fn=os.setsid)允许我使用os.killpg(p.pid,signal.SIGTERM)终止进程 但是,如果命令恰好是类似于setsid sleep 10000的内容,则进程不会终止

我使用以下命令启动Python子流程:

p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, start_new_session=True)
根据,
start\u new\u session=True
(等同于
preexec\u fn=os.setsid
)允许我使用
os.killpg(p.pid,signal.SIGTERM)
终止进程


但是,如果
命令
恰好是类似于
setsid sleep 10000
的内容,则进程不会终止。在Python中,我怎样才能终止这样的子进程?

可能重复为什么使用shell=True?@padraiccnningham,因为我需要执行shell命令,而不仅仅是启动进程。我不需要特别使用shell=True,但我需要使用一些允许我使用sh或bash运行命令的东西。