0

I have a python routine python.py which basically writes a command string contained in the file Command_text.txt and launches it from terminal, executing:

command = 'bash Command_text.txt' os.system(command)

Now, the command contained in the Command_text.txt is mpirun which launches a series of parallel python scripts. Now, if i launch the python.py routine from the shell I can simply kill it pressing Ctrl+C. If I use the command nohup python.py & the situation is more complicated as if I ps my processes I need to find and kill the ones with CMD python bash and mpirun to definitely kill all the job (which means all the following parallel python computations), as shown in the image below:

enter image description here

Now my question is: is there a way to kill the python.py original process automatically killing afterwards the relative bash and mpirun ones as when pressing Ctrl+C?

Thanks in advance for the answer!

Rocco B.
  • 117
  • 1
  • 12
  • 2
    I've previously used the `signal` module to 'listen' for SIGKILL or SIGTERM signals from the command line and then run some code if these signals are received such as `os.kill(pid, signal.SIGKILL)`, this may help as a starting point? – tda Sep 05 '18 at 13:38
  • This question is somewhat duplicated but I read it as, when I press `Ctrl+C` in Python, can I also kill the child processes automatically... and that is not answered in the dupe? – tda Sep 05 '18 at 13:55

0 Answers0