title: Do I have to close inherited handle later owned by child process?
body: <p>Microsoft played safe here. In their article, <a href="http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx" rel="noreferrer">"Creating a Child Process with Redirected Input and Output"</a>, they are saying:</p>
  
  <blockquote>
    <p>The remaining open handles are cleaned up when this process terminates.<br>
    To avoid resource leaks in a larger application, close handles explicitly. </p>
  </blockquote>
  
  <p>Which is perfectly useless. What handles? In which process?</p>
  
  <hr>
  
  <p>I want to get my head around it.</p>
  
  <p>When a handle is created in parent process with <code>SECURITY_ATTRIBUTES.bInheritHandle = TRUE</code>, a child process can see and use it, and the handle has the same value and access rights in both processes.</p>
  
  <p><strong>But is it the same handle, or is it a copy that happen to have same numerical representation?</strong></p>
  
  <p>If I pass a <code>hRead</code> handle to a child process so that it can read from a pipe, and the child process closes the handle, <strong>do I also need to close it from the parent process?</strong> Will it not wipe the pipe from under the child process?</p>
  
  <p>My experiments show that <code>CloseHandle</code> returns success when trying to close a <code>hRead</code> handle passed to the child after the child has closed it. This argues strongly for Yes, you should close it. However, I would appreciate a more solid advice here.</p>