问题描述
我正在寻找一种轻巧,快速,简单的方法来处理Linux机器上某些程序之间的进程间通信.
I'm searching for a light-weight, fast and easy way to handle Inter Process Communication between some programs on a Linux machine.
当前,我正在考虑命名管道,因为它是由操作系统本身提供的.关于性能或可用性是否有任何警告?
Currently, I'm thinking Named Pipe, because it's provided by the OS itself. Are there any caveats about the performance or usability?
共享内存会更好吗?
我认为我不需要超级复杂的框架.
I don't think I need a super-complex Framework.
请指出正确的方向,谢谢!
Please point me in the right direction, thanks!
更新:我想构建一个小程序(守护程序),该程序告诉其他程序(它本身启动)暂停,向后报告其状态,停止等.
Update:I want to build a small program (daemon) that tells other programs (which it itself starts) to pause, report their status back, stop etc.
因此,应该通知另一个程序新命令正在等待它.管道不是很理想,是吗?
So the other program should be notified that a new command is waiting for it. A pipe is not ideal for that, is it?
推荐答案
Boost有一个不错的 InterProcess 库,它是跨平台的并且非常直观.
Boost has a nice InterProcess library that is cross-platform and quite intuitive.
尽管我只是在玩弄它,所以那里可能会有更好的选择.
I have only toyed with it though, so there might be better alternatives out there.
但是,如果您真的不需要共享内存,我会坚持使用消息传递方法.您将避免出现僵局和竞争状况.管道原理确实很棒,甚至允许出现懒惰行为,这可能会节省大量的处理工作,具体取决于手边的事情!
However, if you don't really need shared memory, I would stick with a messaging approach. You'll avoid deadlocks and race conditions. The pipe principle is really great, and it even allows for lazy behaviors which may save you a lot of processing depending on the matter at hand!
这篇关于进程间通信建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!