2

I have a python program that is running in process A; and I have a shell script like this:

#!/bin/bash

# Kill the process A
# Do something...
# Start the process A

Actually I want to execute the above shell script from my python program (process A) to kill the process A, do some operations and restart the python program again. I have used the subprocess module to achieve this:

subprocess.Popen("./script.sh")

The problem is that when the shell script code kills the process A, the process in which the shell script is running, is killed too and the operations is not done.

Now my question is How can I start a process B from process A and kill the process A from within the process B, but the process B continues running?

s ahmad ef
  • 57
  • 6
  • Sounds like [Catch 22](https://en.wikipedia.org/wiki/Catch-22_(logic)). –  Apr 22 '18 at 06:59
  • 1
    Sounds pretty complicated to re-run a process from the shell. Why not do it from within the python program. This link might help: https://stackoverflow.com/questions/49663124/cause-python-to-exit-if-any-thread-has-an-exception/49665590#49665590 – Haris Nadeem Apr 22 '18 at 07:08
  • https://stackoverflow.com/q/27624850, https://stackoverflow.com/q/13592219, https://stackoverflow.com/q/35831291, etc. – djvg Mar 31 '22 at 07:21

0 Answers0