管道与消息队列
Linux 中的消息队列和管道有什么区别?
What is the difference between message queues and a pipe in Linux?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Linux 中的消息队列和管道有什么区别?
What is the difference between message queues and a pipe in Linux?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
我突然想到,假设您谈论的是 posix 消息队列(不是 SysV 消息队列):
select()
,poll()
,epoll()
和mqd_t
上的朋友。Off the top of my head and assuming you talk about posix message queues (not the SysV ones):
select()
,poll()
,epoll()
and friends on themqd_t
.它们确实是非常不同的东西。
最大的实际区别是管道没有“消息”的概念,它只是一个用于写入字节和读取字节的管道。接收端必须有办法知道程序中哪些数据构成“消息”,并且您必须自己实现。此外,字节的顺序是定义的:字节将按照您输入的顺序出现。而且,一般来说,它有一个输入和一个输出。
消息队列用于传输“消息”,消息具有类型和大小。因此接收端只需等待某一类型的“消息”,而不必担心这是否完整。多个进程可以向同一个队列发送数据并从同一个队列接收数据。
请参阅
man mq_overview
和/或man svipc
了解更多信息。They are very different things, really.
The biggest practical difference is that a pipe doesn't have the notion of "messages", it's just a pipe to
write()
bytes to andread()
bytes from. The receiving end must have a way to know what piece of data constitute a "message" in your program, and you must implement that yourself. Furthermore the order of bytes is defined: bytes will come out in the order you put them in. And, generally speaking, it has one input and one output.A message queue is used to transfer "messages", which have a type and size. So the receiving end can just wait for one "message" with a certain type, and you don't have to worry if this is complete or not. Several processes may send to and receive from the same queue.
see
man mq_overview
and/orman svipc
for more information.