0

Imagine we have two scripts: A.py (which is currently running) and B.py (which is not running)

Is there a way that when we kill A.py (by doing CTRL-C or kill -9 PID_A.py), the script B.py starts automatically?

Thank you in advance for your help

  • Not really, no. You can have a watchdog process look at the process listing and do things when some specific processes change state, but that's clearly not a turnkey solution. – tripleee Nov 26 '20 at 13:40
  • Does this answer your question? [How to fire a command when a shell script is interrupted?](https://stackoverflow.com/questions/14702148/how-to-fire-a-command-when-a-shell-script-is-interrupted) –  Nov 26 '20 at 13:54
  • Control-C sends `SIGINT` to every process in the foreground group, which may include both `A.py` and `B.py`, and `kill -9` should *not* be used in normal operation. You probably want to create a single program (a shell script would suffice) that runs `A.py` followed by `B.py`, such that *it* runs `A.py` and blocks until `A.py` exits, at which point *it* continues by running `B.py`. – chepner Nov 27 '20 at 23:04
  • Thank you everyone, I will try these solutions – Vinorth Nov 30 '20 at 09:43

0 Answers0