管道和消息队列之间有哪些区别?

发布于 2024-08-25 19:36:55 字数 180 浏览 10 评论 0原文

管道和消息队列之间有什么区别?

请从vxworks & 解释两者。 UNIX 视角。

我认为管道是单向的,但消息队列不是。

但是管道内部不使用消息队列,那么为什么管道是单向的而消息队列不是?

您能想到的其他差异是什么(从设计或使用或其他角度)?

What are all the differences between pipes and message queues?

Please explain both from vxworks & unix perspectives.

I think pipes are unidirectional but message queues aren't.

But don't pipes internally use message queues, then how come pipes are unidirectional but message queues are not?

What are the other differences you can think of (from design or usage or other perspectives)?

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

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

发布评论

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

评论(5

无戏配角 2024-09-01 19:36:55

消息队列有:

  • 单向
  • 固定数量的条目
  • 每个条目都有最大大小
  • 所有队列内存(#条目 * 条目大小)在创建时分配
  • 类似数据报的行为:读取条目会将其从队列中删除。如果您不读取全部数据,则其余数据都会丢失。例如:发送20字节的消息,但接收方读取了10字节。剩余的 10 个字节将丢失。
  • 任务只能使用 msqQReceive 在单个队列上挂起(有多种方法可以使用替代 API 来更改它)
  • 发送时,如果队列已满,您将挂起(并且不执行 NO_WAIT)
  • 接收时,如果队列已满,您将挂起为空(并且您不执行 NO_WAIT)
  • 支持超时

接收和发送管道

  • 是消息队列之上的一层 <--- 单向!
  • 具有最大数量的元素,并且每个元素具有最大大小,
  • 这不是流接口。数据报语义,只需列出消息队列
  • 读取时,将挂起直到有数据要读取
  • 写入时,将挂起直到底层消息队列中有空间
  • 可以使用选择设施在多个管道上等待

这就是我现在能想到的。

Message Queues are:

  • UNIDIRECTIONAL
  • Fixed number of entries
  • Each entry has a maximum size
  • All the queue memory (# entries * entry size) allocated at creation
  • Datagram-like behavior: reading an entry removes it from the queue. If you don't read the entire data, the rest is lost. For example: send a 20 byte message, but the receiver reads 10 bytes. The remaining 10 bytes are lost.
  • Task can only pend on a single queue using msqQReceive (there are ways to change that with alternative API)
  • When sending, you will pend if the queue is full (and you don't do NO_WAIT)
  • When receiving, you will pend if the queue is empty (and you don't do NO_WAIT)
  • Timeouts are supported on receive and send

Pipes

  • Are a layer over message Queues <--- Unidirectional!
  • Have a maximum number of elements and each element has maximum size
  • is NOT A STREAMING INTERFACE. Datagram semantics, just list message Queues
  • On read, WILL PEND until there is data to read
  • On write, WILL PEND until there is space in the underlying message queue
  • Can use select facility to wait on multiple pipes

That's what I can think of right now.

何其悲哀 2024-09-01 19:36:55

我还在 UNIX 中的 IPC 中发现了这种差异。它指出它们之间的区别在于消息队列和管道首先在数据包中存储/检索信息。而管道则一个字符一个字符地执行。

消息队列:

消息队列:类似于管道的匿名数据流,但存储
并检索数据包中的信息。

管道

管道:通过标准输入和接口连接的双向数据流
输出并逐字符读取

我也在这里发现了这个问题:管道 vs 消息队列

I also found this difference in IPC in UNIX. It states that the difference between them is that Message queues and pipes is that the first stores/retrieves info in packets. While pipes do it character by character.

Msg queue:

Message queue: An anonymous data stream similar to the pipe, but stores
and retrieves information in packets.

Pipe

Pipe: A two-way data stream interfaced through standard input and
output and is read character by character

I also found this question here: Pipe vs msg queue

善良天后 2024-09-01 19:36:55

vxWorks 文档说:“VxWorks 管道与 UNIX 管道有很大不同”,他们不是在开玩笑。 这是手册页

看起来,可以毫不夸张地说,Unix 管道和 vxWorks 管道之间唯一的相似之处在于它们都是 IPC 的一种形式。功能不同,API 不同,实现也肯定有很大不同。

"VxWorks pipes differ significantly from UNIX pipes", says the vxWorks documentation, and they ain't kidding. Here's the manpages.

It looks like it would not be exaggerating much to say that the only similarity between Unix pipes and vxWorks pipes are that they're a form of IPC. The features are different, the APIs are different, and the implementations are surely very different.

峩卟喜欢 2024-09-01 19:36:55

消息队列和管道的对比:
- 一个消息队列可用于双向传递数据
- 消息不需要以先进先出的方式读取
但可以选择性地处理
来源:参见 http://www.cs.vsb.cz/grygarek/dosys/ IPC.txt

Comparison of message queues and pipes:
- ONE message queue may be used to pass data in both directions
- the message needn't to be read on first in-first out basis
but can be processed selectively instead
source: see http://www.cs.vsb.cz/grygarek/dosys/IPC.txt

花心好男孩 2024-09-01 19:36:55

MQ 具有内核持久性,并且可以由多个进程打开。

MQs have kernel persistence, and can be opened by multiple processes.

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