Linux下进程间最低延迟通知方法
我正在寻找最低的延迟 IPC,它允许将一个进程置于睡眠状态并允许其他进程唤醒它。
我正在寻找延迟最低的方法。到目前为止一些可能的方法:
- 将一个字节写入管道并从中读取它。
- 将一个字节写入套接字并从中读取它。
- 发送信号(kill)并等待它(sigwait)
- 使用 sem_post/sem_wait
还有其他更好的想法吗?
任何特定于 Linux 的解决方案都可以。
I'm looking for the lowest latency IPC that allow to put one process to sleep and allow other process to wake it.
I'm looking for the lowest latency method. Some possible methods so far:
- Writing a byte to a pipe and reading it from it.
- Writing a byte to a socket and reading it from it.
- Sending a signal (kill) and waiting for it (sigwait)
- Using sem_post/sem_wait
Any other better ideas?
Any solution that is Linux specific is fine as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说...操作系统方法之间几乎没有区别。
设置:
然后通知其他进程。
结果:
信号量(sem_wait/sem_post - 内核 - futex):
信号(kill/sigwait)
管道(管道 + 写/读)
套接字(套接字对 + 写/读)
作为参考忙碌等待:
Generally... There is almost no difference between the OS methods.
Setup:
and then notifies other process.
Results:
Semaphore (sem_wait/sem_post - kernel - futex):
Signal (kill/sigwait)
Pipe (pipe + write/read)
Socket (socketpair +write/read)
As a reference busy waiting:
使用@Artyom 提供的相同代码,但使用更现代的硬件。
CPU:i9-9900k,关闭C/S/P状态并将扩展策略设置为
性能
,保持核心以最大频率运行( 〜5GHz)。操作系统:Preempt-RT修补Linux内核5.0.21,提供更好的实时性能。
CPU亲和性:两个进程分别运行在两个独立的核心,远离不相关的进程并中断AMSP。
结果:
Semaphore (sem_wait/sem_post - kernel - futex):
Signal (kill/sigwait)
Pipe (pipe + write/read)
Socket (socketpair +write/read)
作为参考忙等待:
Using the same code provided by @Artyom, but in a more morden hardware.
CPU: i9-9900k, closing C/S/P-state and set scaling policy as
performance
which keeps cores running at the maximum frequency(~5GHz).OS: Preempt-RT patched Linux with kernel5.0.21, providing better real-time performance.
CPU affinity: two processes apartly running in two isolated cores, which keep away from irrelevant processes and interrupts AMSP.
Results:
Semaphore (sem_wait/sem_post - kernel - futex):
Signal (kill/sigwait)
Pipe (pipe + write/read)
Socket (socketpair +write/read)
As a reference busy waiting: