Difference between Pipes and Message Queues

Pipes and Message Queues are both Inter-Process Communication (IPC) mechanisms in Unix/Linux systems. Pipes provide a simple unidirectional byte stream between processes, while message queues provide a more flexible, bidirectional mechanism for exchanging discrete messages with optional priorities.

Unix Pipes

A pipe provides a unidirectional flow of data between processes. It is created using the pipe() function, which returns two file descriptors − one for reading and one for writing. Both the sender and receiver processes must be running simultaneously for a pipe to function.

Message Queues

A message queue allows a sender process to write discrete messages that can be read by one or more receiver processes. It is created using msgget() and is implemented as a linked list stored within the kernel. Each message queue has a unique identifier, and messages can have priorities for selective retrieval.

Pipe (Unidirectional) Sender Receiver One direction only FIFO order, no priorities Both processes must be running pipe() → fd[0] read, fd[1] write Message Queue (Bidirectional) Process A Process B Queue Both directions Any order, supports priorities Writer can exit before reader msgget() → queue identifier

Key Differences

Feature Pipe Message Queue
Direction Unidirectional Bidirectional
Creation pipe() → two file descriptors msgget() → queue identifier
Data Order FIFO only Any order (selective retrieval)
Priorities Not supported Supported (via message type)
Process Presence Both sender and receiver must be running Writer can exit; reader reads later
Persistence Deleted when no linked process exists Persists until explicitly deleted
Max Message Size ~4096 bytes ~8192 bytes

Conclusion

Pipes are simple and efficient for unidirectional communication between related processes. Message queues are more flexible, supporting bidirectional communication, message priorities, and persistence, making them suitable for complex multi-process applications.

Updated on: 2026-03-14T16:42:01+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements