1
我有三个*的.py脚本命名为:如何杀死在GNOME终端子
- terminal_starter,
- subprocess_in_terminal,
- ctrlc_sender
分别与下面的代码:
terminal_starter.py
import subprocess
import os
p = subprocess.Popen(['gnome-terminal -e "python subprocess_in_terminal.py"'], shell=True)
gpid = os.getpgrp()
ppid = os.getpid()
p1 = subprocess.Popen(["python ctrlc_sender.py " + str(gpid) + " " + str(ppid)], shell=True)
while 1:
pass
subprocess_in_terminal.py
import time
while 1:
print "Subprocess in terminal."
time.sleep(1)
ctrlc_sender.py
import signal
import os
import sys
import time
gpid = sys.argv[1]
ppid = sys.argv[2]
for i in range(10):
print "Killer says: I will kill " + gpid + "and " + ppid
time.sleep(1)
os.killpg(int(gpid), signal.SIGTERM)
os.kill(int(ppid), signal.SIGTERM)
我要杀死subprocess_in_terminal.py,但我不能。
我在Ubuntu 16.04 LTS和Python 2.7上运行这些脚本。
任何帮助,将不胜感激。
请注意,Ctrl-C发送'SIGINT',而不是'SIGTERM'。 – melpomene