On Windows, how does console window ownership work?

Posted by shroudednight on Stack Overflow See other posts from Stack Overflow or by shroudednight
Published on 2010-05-11T00:17:52Z Indexed on 2010/05/11 0:24 UTC
Read the original article Hit count: 528

When a console application is started from another console application, how does console ownership work?

I see four possibilities:

  1. The second application inherits the console from the first application for its lifetime, with the console returning to the original owner on exit.
  2. Each application has its own console. Windows then somehow merges the content of the two into what the "console" visible to the user
  3. The second application get a handle to the console that belongs to the first application.
  4. The console is placed into shared memory and both applications have equal "ownership"

It's quite possible that I missed something and none of these four options adequately describe what Windows does with its consoles.

If the answer is close to option 4. My follow-up question is which of the two processes is responsible for managing the window? (Handling graphical updates when the screen needs to be refreshed / redrawn, etc)

A concrete example: Run CMD. Then, using CMD, run [console application]. The [console application] will write to what appears to be the same console window that CMD was using.

© Stack Overflow or respective owner

Related posts about Windows

Related posts about console