How to make sure that child process terminates when panicking

Nothing in the parent process can absolutely guarantee this. Your panic handler may never run - your program could be interrupted by an oomkill (on Linux), for example, or the administrator may force-terminate it (SIGKILL or its Windows equivalent), preventing your cleanup code from running.

Doing this right requires cooperation either from the child process, or from a process management tool. There are a few ways to do that depending on what OS or OSes you want to target and just how reliable you want it to be. What the child process is doing may also make a difference. Can you say more about your use case?

1 Like