Difference between Pipes and Message Queues

Unix system uses pipes, to establish inter process communication. A pipe provides an unidirectional flow of data. A pipe is created using the pipe() function.


#include int pipe(int fd);  

A pipe ()function returns two file descriptors, fd[O] and fd[1]. The fd[0] is open for reading from and fd[1] is open for writing to the pipe. The data flows from one end of the pipe to the other end. The pipe function returns ‘0’ on success or -1 on error.

Message Queues:
A Message Queues, allow one or more processes to write message to be read by other processes. A message queue is implemented as a linked list of messages, and is stored within the Kernel. Each message queue is identified by a message queue identifier. The Kernel keeps track of all the message queues created in a system.

Difference between Pipes and Message Queues:

S.NO Pipes Message Queues
1. Pipe is a form of Unix IPC that provides flow of data in one direction. Message queues is a form of system VIPC that store a linked list of messages
2. Creating a pipe using pipe() function, returns two file descriptors, one for reading another for writing. Creating a message queues using msgget() function returns a message queue identifier.
3. Pipes and FIFOs are unidirectional, i.e., the data can flow in one direction only. Message queues are bidirectional i.e., the data can flow in both directions.
4. With Pipes and FIFOs, the data must be fetched in first in first out order. With message queues the messages can be read in any order that is consistent with the values associ ated with the message types.
5. Priorities can’t be assigned to the messages. Priorities can assigned to the messages by associ ating a priority to a type or range of types.
6. With Pipes and FIFOs, there must be some process waiting for a message to be written over the pipes and FIFOs i.e., both a reader process and a writer must exist. With message queues a process can write the messages to a queue then exit, so that the messages can be read by another process at a later time.
7. Pipes are completely deleted from the system, when the last process having reference to it terminates. Message queue and its contents remain in the system on process termination until they are specifically read or deleted by some process calling mcgregor magento, by executing the ipcrm(1) command or by rebooting the system.
8. The maximum number of bytes that can be written to a pipe of FIFO is 4096 bytes. The maximum message size that can be written to a message queue is 8192 bytes.
9. A major advantage of using named pipes is that they provide a useful way to send one-line requests to an OpenEdge background session running a message handler procedure better Performance. Message queues enable asynchronous communication, which means that the endpoints that are producing and consuming messages interact with the queue, not each other.
10. Multiple users can send requests through the same named pipe and each request is removed from the pipe as it is received. Increased Reliability.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.