两个程序之间的消息传递

两个程序之间的消息传递

本文介绍了两个程序之间的消息传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有两个独立的 C++ 程序,一个主程序和一个从属程序.master 使用 boost::interprocess 将一些数据写入共享内存,然后启动可以从内存中读取的 slave.

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?

背景:这是我上一个问题的延续 这里...

推荐答案

您可以使用 posix 消息队列,或者更好的是 提升消息队列.

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

这篇关于两个程序之间的消息传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:15