When creating a child process in C ++ using the Windows API, you can enable the inheritance of handles from parent to child. In the Microsoft example, Creating a child process with redirected inputs and outputs redirecting the child process' std in / out to channels created by the parent, you must enable inheritance for the redirect channels.
I am working on a small demo class that runs an external executable, reads the output, and then returns it to the caller (which writes the returned output to a file). I am trying to create a timeout function where it will only block for a while before calling TerminateProcess() for the child and continue life.
However, I found that by allowing descriptor inheritance, the child process also has a descriptor (visible from Process Explorer ) in the output file. I do not want the child process to receive this descriptor, but the parent in this case (this demo class) also does not know about this descriptor, so I can not use SetHandleInformation() to immediately remove the output file to exclude it from inheritance.
I am sure that there should be a better way to inherit ONLY the specific pens that I want, avoiding the imposition of a “blanket” that skips unintentional and unwanted calls. Unfortunately, I could not find a solution by browsing as many related MSDN articles as possible and finding Googled in a state of despondency.
At least I need to do something to remove the descriptors from the child, not necessarily having these descriptors inside the demo class (they are used by the calling class, and this demo class does not have an explicit knowledge of its existence).
Any solutions for more selective inheritance? I am particularly interested in a solution that allows me to specifically declare which descriptors are inherited, and all unspecified descriptors will not be inherited if such a solution exists.
Thank you.
c ++ windows parent-child handle
Kevenk
source share