不同IPC机制的使用

发布于 2024-10-15 02:39:40 字数 178 浏览 7 评论 0原文

我是一名 C++ 程序员。

我想知道一个实时场景,我们可以使用不同的 IPC 机制,例如 PIPE/命名、共享内存。

我大致知道哪里可以使用套接字和消息队列。但对于 PIPE/Named PIPE 和共享内存我没有任何想法。

这只是为了了解不同的 IPC 机制及其用法。

谢谢,

I am a c++ programmer.

I wanted to know a real time scenario where we can use different IPC mechanisms like PIPE/Named, Shared Memory.

I roughly know where I can use socket and message queue. But for PIPE/Named PIPE and shared memory I am not getting any idea.

This is just for understanding about different IPC mechanisms and their usage.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌辣 2024-10-22 02:39:40

我需要使用命名管道与作为守护进程运行的 Erlang 虚拟机进行通信。

我相信它们正在慢慢被“套接字对”取代,因为它提供双向通信,与管道不同,管道只是单向的,除非我们创建两个不同的管道。

共享内存仍在大型服务器应用程序中使用,因为它将是多处理器系统上所有其他机制中最快的,但通常很难以正确的方式实现。

仅当需要通过网络进行通信时才需要使用套接字。

再次归结为一件事“使用最适合您的应用程序的机制

I needed to use Named pipe for communicating with my Erlang Vitual Machine which was running as a daemon.

I believe they are being slowly replaced by "socketpairs" as it offers bi-directional communication unlike pipes which is only unidirectional unless we create two different pipes.

Shared Memory are still in use in large Server applications as it will be the fastest of all other mechanisms on a multiprocessor system but are usually difficult to implement in the right way.

And use of sockets becomes necessary only when communication across a network is required.

Again it comes down to one thing "Use the mechanism which suits you best for the application"

清醇 2024-10-22 02:39:40

我们公司有一些使用共享内存的软件。它使用它将数据从一个进程流式传输到其他一些进程。可以使用套接字,但由于它是一对多,因此应该为每个消费者进程创建一个单独的套接字,这并不是真正的最佳选择。在现代计算机上,使用共享文件可能可以完成这项工作,但该软件是在 90 年代中期开发的,当时磁盘速度相当慢,并且该软件具有非常严格的延迟要求。它使用一种循环缓冲区,生产者进程在其中写入数据。信号量用于同步,因此其他进程不会看到部分更新的数据。

不过,在大多数现代软件中,通常使用线程而不是使用共享内存的多个进程。

至于管道,最常见的用途是外壳管道:

ps ax | grep java

我相信命名管道很大程度上被套接字取代。即使它们仍然有它们的用途,我也不知道它们中的任何一个。

您可能还希望阅读 Eric 所著的 《Unix 编程艺术》的相关章节史蒂文·雷蒙德.它很好地概述了 Unix IPC 方法及其用途。

We have some software in our company that uses shared memory. It uses it to stream data from one process to some other processes. Sockets could be used for it, but since it is one-to-many, a separate socket should be created for each consumer process which isn't really optimal. On modern computers using a shared file would probably do the job, but this software was developed in mid-90s when disks were pretty slow, and this software has pretty strict latency requirements. It uses a kind of circular buffer where the producer process writes its data. Semaphores are used for synchronization so other processes won't see partially updated data.

In most modern software threads are usually used instead of multiple processes using shared memory, though.

As for pipes, the most common use for them are shell pipes:

ps ax | grep java

I believe named pipes are largely replaced by sockets. Even if they still have their uses, I'm not aware of any of them.

You may also wish to read the relevant chapter of the Art of Unix Programming by Eric Steven Raymond. It gives very nice overview of Unix IPC methods and their uses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文