0

I have a shell script which in turn starts a python script. Python script further creates a process pool and does its stuff.

conda activate app_env
... some other shell commands ...

clean() {
   # make sure all process created by python and python itself
   # gets killed
}

trap clean SIGINT

python start_server.py

When someone manually tries to exit the script using ctrl+c, I need to make sure that all the processes started by python get killed. Is there a way where I could all the child process started by the shell script in one go or may be step by step?

Right now, I listen for the ctrl+c signal and then execute the cleaning function. After I have detected the ctrl+c signal, how do I kill the processes started by python i.e started by this shell script

Amanda
  • 2,013
  • 3
  • 24
  • 57

1 Answers1

0

If killing the python script would kill the processes you could use a trick with GNU screen. Start the python process as:

screen -S session_name -d -m your_python_process

and kill it in clean() with:

screen -X -S session_name quit

If this is not an option because killing the main python script would not kill all processes then maybe you should have a look at this SO question: How to kill zombie process or this one: killing Parent process along with child process using SIGKILL