English 中文(简体)
What are all the differences between pipes and message queues?
原标题:

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

问题回答

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.

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

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

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

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





相关问题
Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Function to create the array by reading the file

I am creating scripts which will store the contents of pipe delimited file. Each column is stored in a separate array. I then read the information from the arrays and process it. There are 20 pipe ...

Compare characters at the end of the string C++

This program supposed to find command line arguments entered on Unix which ends with “.exe”. For some reason it doesn t work. Here is the code: int main( int argc, char* argv[] ) { for ( int ...

Batch Job Dependencies Using Open Source/Free Software

I run a large data warehouse plant where we have a lot of nightly jobs running concerruently however many have dependencies on a extract or data load process before they start. Currently we use an ...

Writing application for both Unix and Windows

I ll write a program for Interactive UNIX (http://en.wikipedia.org/wiki/INTERACTIVE_UNIX). But in a year it will be ported to Windows. I ll write it in ANSI C and/or SH-script. When it runs on Windows ...

Development Environment in Windows [closed]

What are your recommendations for setting up a development environment in Windows, especially when not using an IDE. I am attempting to familiarize myself with Windows, and I feel a bit lost. What ...

热门标签