I have been trying to understand the difference between these two process creation flags. The msdn documentation is not clear about the distinction.
The difference is in what the started process can do. In both cases it won't have a console. But with the CREATE_NO_WINDOW
option it can call AttachConsole(ATTACH_PARENT_PROCESS)
and get access to the parent's console window (if available). That explicitly will not work when you specify DETACH_PROCESS
. The only option then is for the started process to use AllocConsole()
to create its own console.
Or in other words, you can be sure that the started process will never be able to chatter into your own console by using DETACH_PROCESS
.
I have not tested what Hans Passant said about AttachConsole(ATTACH_PARENT_PROCESS)
. However, I have found another difference based on testing.
Let's define a process tree to better explain what I mean:
A
|
+-- B
|
+-- C
With DETACH_PROCESS
, only the started process (B) has no console — by default. If the started process starts console child processes (C), then each of those child process will be started in a new console. Furthermore, the started process B (or its children C) can still create a console by calling AllocConsole
.
CREATE_NO_WINDOW
is a "nuclear option" that's stronger than DETACH_PROCESS
. Even the started process' children (C) don't get a console, not even if they call AllocConsole
. Furthermore, Ctrl-C'ing the topmost process (A) won't terminate B and C, so it seems that CREATE_NO_WINDOW
also includes an effect similar to starting a new process group.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.