I am trying to do the equivalent of the following using Python subprocess:
>cat /var/log/dmesg | festival --tts &
[1] 30875
>kill -9 -30875
Note that I am killing the process group (as indicated by the negative sign prepending the process ID number) in order to kill all of the child processes Festival launches.
In Python, I currently have the following code, wherein two processes are created and linked via a pipe.
process_cat = subprocess.Popen([
"cat",
"/var/log/dmesg"
], stdout = subprocess.PIPE)
process_Festival = subprocess.Popen([
"festival",
"--tts"
], stdin = process_cat.stdout, stdout = subprocess.PIPE)
How should I kill these processes and their child processes in a way equivalent to the Bash way shown above? The following approach is insufficient because it does not kill the child processes:
os.kill(process_cat.pid, signal.SIGKILL)
os.kill(process_Festival.pid, signal.SIGKILL)
Is there a more elegant way to do this, perhaps using just one process?
os.setprgid
– Catheterize