I have a python process, which spawns a git (git clone) child process, which in turn spawns several child processes itself. Here, I want to kill all processes in the process tree rooted by git, without killing the python process.
Possible solutions with caveats:
- Traverse the child process tree of
pythonusing/proc/<pid>recursively.
In this case, how can I be sure that any process in this process hierarchy hasn't spawned a child process before it being killed, in which case the child becomes an orphan (race condition)?
- Kill the process group of the
pythonprocess, which includesgitand every other descendant.
In this case, python process is killed too, which I don't want to happen.
Is there any way to reliably kill all processes in the process hierarchy rooted by the python process, but not the python process itself?