I am trying to write a python program to test a server written in C. The python program launches the compiled server using the subprocess
module:
pid = subprocess.Popen(args.server_file_path).pid
This works fine, however if the python program terminates unexpectedly due to an error, the spawned process is left running. I need a way to ensure that if the python program exits unexpectedly, the server process is killed as well.
Some more details:
- Linux or OSX operating systems only
- Server code can not be modified in any way