As I understand, on Windows, the process that creates a named pipe, owns the "server" handle (one side of the pipe). Is it possible to split pipe creation from actually using it (opening it for reading and writing)?
I need to create a named pipe with one process, but use two other processes to open it for reading and writing. But I'm concerned, that when the process that creates the pipe exits, the pipe gets removed from the file system.
Named pipes exist solely because of the sort of scenario you're talking about.
With anonymous pipes (see CreatePipe
), it is necessary that there be a "factory" somewhere that creates the pipe, and then at least one of the handles is handed off to a "client" somewhere (within the same process or not).
With named pipes (see CreateNamedPipe
), it is not necessary to have the "factory" which creates and distributes the handles. Instead, the "server" side of the named pipe directly does a CreateNamedPipe
with the correct pipe name, and the "client" side of the named pipe directly uses CreateFile
with the pipe name to open the client side of the named pipe. Each side deals with its error conditions appropriately. If implemented correctly, no additional coordination is necessary.
If your application requires a "factory" process for the named pipe (it shouldn't), then you'll have to figure out your own way to provide the handles to the "client" processes in such a way that the pipe is not destroyed in the interim. Or you can use the pipe name instead of distributing the handles, but you may have to explicitly coordinate between the processes using something like a named event (see CreateEvent
).
If this doesn't answer your question, please update your question with more details.