I have a Python script which starts a subprocess another Python script using subprocess.Popen(). This subprocess starts another subprocess( another Python script) using Popen. Script A calls script B which calls script C. If I kill process script B using os.kill() will it terminate the process running script C. If not is there any way to do that.
As it stands, if script A kills B using os.kill then C will not itself be killed.
In order to ensure this, script B could take care of killing C when it exits
# this is in script B
import functools, atexit
def kill_children(*pids):
import os, signal
for pid in pids or []:
os.kill(pid, signal.SIGTERM)
# we start a process for C
c_pid = ...
# kill C when we we exit
atexit.register(functools.partial(kill_children, c_pid))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With