Can you share some code?
On Linux, the trick is to kill the whole process group, not just a process of it. This is achieved by sending a KILL signal to the negative PID of the process group’s leader.
So if you start a new process with Setpgid=true, then THAT child process will become its own process group’s leader, and also independent of its parent’s process group! So in this case killing tha parent won’t kill this child.
You’re saying this is a 5-6 level deep process tree - if you want to kill all of it, kill the process group’s leader, and ensure that neither child created a separate process group!