V2: kill child processes on Windows when the parent dies

Open
#556 2 comments 0 reactions 0 assignees View on GitHub

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

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/process

All issues in boostorg/process

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.