views:

216

answers:

3

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)?

A: 

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

Ken
Ken, I'm not sure what you're saying... In the context of vxWorks, pipes can be opened by multiple processes. I'm not sure what kernel persistence means.
Benoit
It appears that vxWorks "pipes" are very different from "pipes" on pretty much every other modern operating system. You can assume my answer applies to every non-vxWorks system. :-)
Ken
Kernel persistence means it persists as long as the kernel does, as opposed to filesystem persistence, process persistence (which pipes have, at least on Unix), etc.
Ken
+2  A: 

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.

Benoit
What is `pend`?
Stephen Nutt
The task is in the pended state, meaning it is waiting for something to occur: in this case, the queue to have something in it (when reading) or have an empty slot (when writing).
Benoit
+1  A: 

"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.

Ken