Message passing between two programs

此生再无相见时 提交于 2019-12-11 03:35:56

问题


Currently I have two standalone C++ programs, a master and a slave. The master writes some data to shared memory, using boost::interprocess, and then launches the slave, which is able to read from the memory.

What I would like to do is to have the slave constantly running, and for the master to send a message to the slave when the memory has been written to and is ready to be read from.

The only way I can think to achieve the same thing is for the slave to constantly check the shared memory for the presence of an object, and when it is detected read from it and delete it. However, this doesn't seem optimal.

Is there a nicer way of achieving the same thing?


Background: This is a continuation of my previous question here...


回答1:


You can use posix message queues, or better yet boost message queues.




回答2:


Why not have them communicate over a unix domain socket? From the other question, you said you were building this on ubuntu, so that won't work immediately on windows.

Boost has support for this in the boost::asio lib, which I suspect uses named pipe sockets when you compile for windows.



来源:https://stackoverflow.com/questions/8900141/message-passing-between-two-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!