FIX: Spawn Hangs When Inheriting Pipe Handle (151071)
The information in this article applies to:
- The C Run-Time (CRT), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
This article was previously published under Q151071 SYMPTOMS
When asynchronously spawning a child process that is inheriting a pipe
handle, the parent process hangs before returning from the spawn call.
CAUSE
When you starting Visual C++ version 4.0, the startup code attempts to
validate the inherited handle values by calling GetFileType for each
handle. With Windows NT, if two write handles for the same object are
passed to the child process, the GetFileType hangs when called for the
second one.
RESOLUTIONNOTE: In order to use the _pipe function to communicate between a parent
and child process, each process must have only one handle open on the pipe,
and each process must be of opposite sense (the parent has a read handle
open, the child has a write handle open). To implement this behavior,
combine the _O_NOINHERIT flag using the bit-wise-OR operator (|) into the
third argument of the _pipe call. Then, use _dup or _dup2 to create an
inheritable copy of the pipe handle you want to pass to the child. Close
the original handle and spawn the child process. Immediately upon returning
from the spawn call in the parent process, close the duplicate handle.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article. This bug was corrected in Visual
C++ 32-bit Edition version 4.2.
Modification Type: | Major | Last Reviewed: | 10/17/2003 |
---|
Keywords: | kbbug kbCRT kbfix KB151071 |
---|
|