I wrote two short programs that use anonymous channels for communication. The parent process shares the channel descriptors by setting the standard I / O descriptors for the child:
ZeroMemory(&m_ChildSI, sizeof(STARTUPINFO));
GetStartupInfo(&m_ChildSI);
m_ChildSI.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
m_ChildSI.wShowWindow = SW_HIDE;
m_ChildSI.hStdError = m_pipeChild.WritePipeHandle();
m_ChildSI.hStdOutput = m_pipeChild.WritePipeHandle();
m_ChildSI.hStdInput = m_pipeParent.ReadPipeHandle();
A child acquires a read read handle with a GetStdHandle call :
hReadPipe = GetStdHandle(STD_INPUT_HANDLE)
My question is: Pipe handles are created by a parent process that calls CloseHandle () on them as soon as the parent and child have completed the conversation.
Does the child also need to call CloseHandle ()? I thought that since these are standard I / O descriptors, they are automatically freed up when the process changes.
thank!
user206705
source
share