There are N-th number of processes (it does not matter, threads, forks, or just programs). They all need to pass some information, for example, about a certain event. That is, it is necessary that there was one place from which they all should take information. How is this usually implemented?
3 answers
Look in the direction of the phrase "publish-subscribe" and "message bus." There you can find a lot of options, choose the taste and the task.
For example,
- If it’s smarter, and with queues and delivery confirmation, an AMQP server, say, RabbitMQ. Or not AMQP and STOMP to use.
- If more primitive - Redis, for example, yes.
- Again, sometimes everything is already in the system. For example, you can often find D-Bus on * nix'ovy desktops. True D-Bus over the network is (although possible) very, very much through the ass and only after a huge file, so the solution is only within one machine.
- And if the office has an XMPP server, it can also be used.
- If without a server, 0MQ (aka ZeroMQ) has pub / sub capabilities.
- Or generally the good old (but little-known) POSIX message queues, if necessary within the same machine.
|
Offhand - through the pipe. You can see how this is implemented, for example in Google Test. There, each test is run in a separate process and the entire interop
with the main process occurs through pipes
(naturally, cross-platform).
|
It turned out that Redis has a similar function.
|