First, the question in title:
Can multiple processes open a named pipe?
The answer is yes. I mean, more than one reader and more than one writer simultaneously.
Now your actual question:
Is there some way my process can Tee off the named pipe it is writing too each time a new subscriber attempts to open the pipe?
I'm not sure what you mean by "tee off" but here is a general answer:
- Because opening the pipe for writing is a blocking operation, until someone else opens it for reading, and because writing to a pipe with no reader triggers a SIGPIPE, your writer (the publisher) can know for sure that there is at least one reader (subscriber).
On the other hand, the writer cannot know whether there are multiple readers at a given time (you can mitigate this by spying the fifo activity with inotify
, though)
- The messages the publisher will send cannot be aimed at a specific reader.
- The content of the message that the publisher writes won't be duplicated among readers (i.e. each reader gets the same message the writer sent). Instead, each reader will read a part of it. For example, if you write "HELLO WORLD" into a pipe with three subscribers (readers), then the first one may receive "HELL", the second one "LORD" and the last one "O W"
[edit] Now that you have clarified your question, what I have written above still applies and we can come to a conclusion: named pipes are clearly not the right tool for your needs.
You probably need broadcast/multicast UDP sockets, or a dedicated messaging system like D-Bus, AMQP brokers, etc.
inotifywait
can help you.inotifywait
. That I create a file that I always append to and other processes usesinotifywait
to pend on that?inotifywait
can help you much. :(