boostorg / boostorg/process

Closing parent console kills detached process in Windows

Open
#186 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Description

I've noticed a strange behaviour when i'm running a "launcher" that execute the following code:
```
#include
#include

namespace bp = boost::process;

bp::child c("./client_service");
c.detach();
return;
```
The child process starts correctly and is kept alive even if the main process returns. But, as soon as the Windows console is closed, the child process dies. This problem occurs only in Windows, while in Linux the code works like a charm. This also occurs using spawn instead of child+detach.
Digging a little bit, this appers related to the [Windows Process Creation Flags](https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags) and the standard parent console inherit fashion. In particular, passing 0 as creation flag to the CreateProcess, makes the child inherit the parent console and so, when it is closed, the child is terminated by the OS. Instead, passing "DETACHED_PROCESS" (0x08), the new process does not inherit its parent's console and continues after cmd is closed. Is this behaviour wanted? Or is it not supposed to happen?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.