V2: kill child processes on Windows when the parent dies
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- cpp
- Domain
- operating-systems
Research direction
Start by tracing the Windows v2 process-creation path around windows/creation_flag.hpp, bp::process, native_handle, CreateJobObjectW, and AssignProcessToJobObject. Compare the suspended-process option described in the issue and determine what handles or lifecycle hooks are available. Done means child and grandchild processes are reliably killed when the parent dies without the stated race.
Written by the indexing model from the issue text.
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
#include <windows.h>
#include <boost/process/windows/creation_flag.hpp>
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.
- Dominant language
- C++
- Stars
- 145
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/process
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in boostorg/process
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100