以下是我的想法:
首先,我使用 subprocess.Popen 创建了一个进程
其次,经过一段时间后,我试图用 Popen.kill ()杀死它
import subprocess
import os, signal
import time
proc1 = subprocess.Popen("kvm -hda /path/xp.img", shell = True)
time.sleep(2.0)
print 'proc1 = ', proc1.pid
subprocess.Popen.kill(proc1)
但是,在 Popen.kill ()之后,“ proc1”仍然存在。 有专家能告诉我怎样解决这个问题吗? 谢谢你的关心。
Thanks to the comments from all experts, I did all you recommended, but result still remains the same.
proc1.kill() #it sill cannot kill the proc1
os.kill(proc1.pid, signal.SIGKILL) # either cannot kill the proc1
还是要谢谢你。
我还在等待你解决这个棘手问题的宝贵经验。