V2: kill child processes on Windows when the parent dies
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Description
@klemens-morgenstern, we already discussed this in https://github.com/boostorg/process/issues/454, but you probably missed my last comment left after the issue was closed. I can't reopen it, so I have opened this new issue to continue the conversation.
Your solution
```C++
#include
#include
auto h = ::CreateJobObjectW(nullptr, nullptr); // don't forget the CloseHandle
bp::process proc(..., boost::process::windows::create_breakaway_from_job);
AssignProcessToJobObject(h, proc.native_handle()); // error handling...
// now do with the job object `h` what you have above
```
seems to have a flaw. If the child process manages to create a grandchild process before AssignProcessToJobObject is called, the grandchild won't be killed be the OS on the main process crash. V1 allowed to include the child process into the main process' group before it runs; for v2 it's not possible. Another option is to create the child process suspended, as recommended here: https://devblogs.microsoft.com/oldnewthing/20131209-00/?p=2433, but to resume it one have to know the main thread handle, that cannot be fetched from bp::process object. So currently there is no solution that works with v2.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.