Difference between Pipes and Message Queues

Unix Pipes

Unix Pipes are used in inter-process communication. A pipe as name suggests provides a unidirectional flow of information. Data flows from one end to another.

Message Queues

Message queue allows to share messages by a sender process to another process (es). A message queue is implemented as a linked list of messages and stored within kernel. Each message has a unique message queue identifier. The kernel keeps a record of message queues present in the system.

The following are some of the important differences between Unix Pipes and Message Queues.

Sr. No.KeyPipeMessage Queue
1ConceptThe pipe is the Unix IPC form to provide a flow of information in one direction.Message Queue is a System VIPC form to store a list of messages.
2CreationA pipe can be created using pipe() function which returns two file descriptors, one is for reading and another is for writing.A message queue is created using msgget() function which returns a queue identifier.
3DirectionThe pipe is unidirectional.A message queue is bidirectional.
4Data FetchingData can be fetched in FIFO, First In First Out manner.Data can be fetched in any order.
5PrioritiesPriorities are not present in pipes.A message can have a priority by attaching a priority number to type(s) of the message(s).
6ReceiverFor a pipe to function, sender and receiver processes should be present to wait for messages to be written and read in a pipe.In a message queue, a writer process can write a message and exit. A reader process can read a message later.
7PersistenceA pipe is deleted from the system if there is no linked receiver/sender process is present.A message queue remains active in the system until explicitly deleted by some process.
8Message SizeA pipe message size can be up to 4096 Bytes.A message queue message size can be up to 8192 Bytes.