views:

555

answers:

2

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 connect 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?

A: 

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.

luvieere
A: 

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.

erikkallen
right, that's what I do ... so you're saying "PipeO" is global, that any process going an talking to "Pipe0" gets the same pipe reference?
halivingston
Yes, as long as you don't mix up the capital letter O and the digit 0.
erikkallen