I’m trying to make two-way many-to-one communication between programs in Linux.
My plan is the following: One program called “driver” that talks with the hardware needs to communicate with an unknown number of applications in Linux. I read that one of the most common ways for inter process communication is “named pipes”.
The question I haven’t found yet is: How new programs should notify the driver that a new program is running so that one more connection (named pipe) between the new program and the driver enstablished?
All programs will be written in C++
Advertisement
Answer
I also think sockets may be a better solution, but if you really want named pipes, I’d do it this way:
The server opens a pipe named channel_request
for reading. Any new client opens it for writing and writes a unique ID. (PID should work). The server reads this id and creates a named pipe called channel_[id]
. The client then opens channel_[id]
for reading and can start receiving data.
Note that linux pipes are unidirectional, so if you want two-way communications as shown in your diagram, you will need to open both a channel_[id]_out
and a channel_[id]_in
.