Are named pipes in Windows (and other OS as well process wide)?
I have this weird scenario:
I wrote a program lets say "Controller.exe" which spawns a bunch of "Workers.exe", then Controller.exe creates a named pipe called "Pipe0" ... through "PipeN".
Then Workers.exe (who are started with a command line arg as the name of the pipe) go c开发者_JAVA技巧onnect to this pipe.
So a customer of this controller.exe to generate load started 5 instances of the program ("controller.exe") which created 5 times the Worker.exe processes
but in my code for Controller.exe I create a named pipe called "Pipe0" ... "PipeN" ... so my question is how is this even working!?
Aren't named pipes OS wide? As in how does Worker.exe know which named pipe "pipe0" to connect to?
I don't know about *NIX, but in Windows they are in the same namespace as named kernel objects (e.g. named mutexes), which is shared by all processes. As for which pipe to listen to, pass that as a command-line argument.
Check out the Named Pipe MSDN Page for a description of the mechanism. In your scenario it is possible that subsequent attempts at creating pipes with the same name result in INVALID_HANDLE_VALUE errors. At least that's what the CreateNamedPipe Function Reference states.
精彩评论