I have a python script to run a few subprocesses, unfortunately, when I tried to kill the subprocess, it doesn't really end and it still runs in the background. This the python code that I start my subprocess with.
p = subprocess.Popen(['sudo', "python3", "networkLogScript.py"],preexec_fn=os.setsid)
px = subprocess.Popen(["python", "testingLog.py"], preexec_fn=os.setsid)
This is how I try to kill the processes:
os.killpg(os.getpgid(p.pid),signal.SIGTERM)
os.killpg(os.getpgid(px.pid),signal.SIGTERM)
p.terminate()
px.terminate()
p.kill()
px.kill()
Sadly, this did not kill the process and it is still running. Would really appreciate any help! Thank you :)