ich drei * Py-Skripte mit dem Namen wie:Wie subprocess in gnome-Terminal töten
- terminal_starter,
- subprocess_in_terminal,
- ctrlc_sender
mit dem folgenden Code jeweils:
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)
Ich möchte subprocess_in_terminal.py töten, aber ich bin nicht in der Lage.
Ich verwende diese Skripte auf Ubuntu 16.04 LTS und Python 2.7.
Jede Hilfe wäre willkommen.
Beachten Sie, dass Ctrl-C 'SIGINT', nicht' SIGTERM' sendet. – melpomene