多个相同进程之间的IPC通信

发布于 2024-11-03 04:42:25 字数 553 浏览 0 评论 0原文

上下文:Linux (Ubuntu)、C

我在一个盒子上生成了几个相同的简约进程。这些进程正在进行一些网络连接,并且大部分时间都停留在poll(或select或其他任何东西 - 我可以根据需要更改它)。

进程的生命周期由 runit 使用 multiwatch 进行监控(如果发生变化)。

有时,随机的一个进程可能会决定向所有其他进程(包括它自己,如果它使事情变得更简单的话)发送一条消息(即一堆数据)。

此外,有时,操作人员可能想从命令行发送这样的消息(假设我可以根据需要编写命令行工具)——再次向每个进程发送这样的消息。

必须保证消息传递。但是,如果任何(或所有)接收者突然消失,它不应该阻止发送者(OTOH,如果他们还活着但很忙,他们最终必须收到消息。)如果接收者进程在轮询中空闲,则必须被消息唤醒。

在不增加太多复杂性的情况下组织这种沟通的最可靠的方法是什么?

注意:由于技术原因,我无法使用 POSIX 信号在进程之间进行通信。

Context: Linux (Ubuntu), C

I have several identical minimalistic processes spawned on a single box. The processes are doing some networking, and spend most of their time stuck in poll (or select or whatever — I can change that as needed).

Processes lifetime is monitored by the runit with multiwatch (if that changes something).

From time to time a random one of the processes may decide that it wants to send a message (i.e. a bunch of data) to all other processes (including itself if it makes things simpler).

Also, from time to time, a human operator may want to send such a message from a commandline (assume that I can write a commandline tool as needed) — again, to each and every process.

Message delivery must be guaranteed. But it should not block sender if any (or all) recipients suddenly vanished (OTOH, if they are alive but busy, they must eventually receive the message.) If recipient process is idling in a poll, it must be awakened by the message.

What is the most robust way to organize this communication without adding a lot of complexity?

Note: For technical reasons I can not use POSIX signals to communicate between processes.

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

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

发布评论

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

评论(2

浪推晚风 2024-11-10 04:42:25

广播和可靠这两个术语有点相反,我认为您必须建立所有可靠的单播连接并自己实现“广播”。

我编写了一些集群软件,其中 LAN 上的节点需要找到彼此并建立可靠的通信 - 其方案如下:

  • 每个进程都配置有相同的端口号和 LAN 广播地址
  • 每个进程都绑定一个 tcp 侦听器随机本地端口
  • 每个进程绑定到指定的本地 UDP 端口,侦听广播
  • 每个进程每隔几秒发送一条消息,宣布其存在、ID(例如 PID)和 TCP 端点
  • 当一个进程发现另一个具有较低 ID 的进程时,它会建立TCP 连接到它,并可选择询问已知对等点的列表。

此后,每个进程都连接到每个其他进程,并且您可以手动实现“可靠广播”。

The terms broadcast and reliable are kind of opposed, I think you'll have to establish all to all reliable unicast connections and implement "broadcast" yourself.

I've written some clustering software where nodes on a LAN need to find each other and establish reliable communication - the scheme for this was as follows:

  • Each process is configured with the same port number and lan broadcast address
  • Each process binds a tcp listener to a random local port
  • Each process binds to the specified local UDP port, listening for broadcasts
  • Each process sends a message announcing its presence, ID (e.g. PID) and TCP endpoint every few seconds
  • When a process discovers another process with a lower ID, it establishes a TCP connection to it, and optionally asks for a list of known peers

After this, every process is connected to every other process, and you can implement "reliable broadcast" manually.

一花一树开 2024-11-10 04:42:25

我知道这个帖子已经很老了,我认为答案可能会对那里的人有所帮助。我使用过 Kbus,发现它非常适合跨多个进程广播消息。它是一个带有用户库的 Linux 内核模块,进程需要使用该库来创建描述符。使用发布/订阅设计模式,使其成为一个解耦系统。

来源:
https://github.com/kynesim/kbus

文档:
https://kbus.readthedocs.io/en/latest/

史密斯

I know this thread is quite old, thought the answer might help someone out there. I have used Kbus and found it to be great for broadcasting messages across multiple processes. It is a Linux Kernel module with a User library that processes needs to use to create descriptors. Uses the Publish/Subscribe design pattern which makes it a decoupled system.

Source:
https://github.com/kynesim/kbus

Docs:
https://kbus.readthedocs.io/en/latest/

Simith

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