So welcome back, guys.
Next IPC technique that we will going to learn in this module is message queue.
So in this module we will going to learn about the concepts of message queue.
As an IPC, we will learn about message queue concepts, we will learn about the APIs that is provided
by Linux operating system for message queue management.
And then we will discuss some of the design aspects regarding how message queue should be used.
And then we will wind up this module with a code walk.
That is, we will going to discuss the steps to implement message queue based inter-process communication
between two processes.
So you can see in this diagram, this diagram essentially captures the functioning of a message queue.
That is how message queue can be used to implement IPC between two processes.
So we have here a process, a which is actually a sender process and is running on a Linux machine.
And we have a process B which is a receiver process and is running on the same Linux machine.
So you can see that between process A and process B, the channel of communication is a message queue.
The process A is a sender process.
That is, it can enqueue the message in the message queue and the messages are then delivered to the
process.
B In the same sequence in which the message was encoded by the process.
A So the process of removing the message from the message queue at the other end is called DQ of a message
and DQ operation is done by the receiver process.
So you can see that message queue is actually a communication channel between the process A and process
B, So Linux or Unix based operating systems provide another mechanism for carrying out Inter-process
communication.
And this mechanism is called message queue.
Processes that is running on the same machine can exchange any data using message queue.
So remember, message queue is a mechanism to implement IPC between processes which are running on the
same machine.
If the processes are running on different machines means there is no other way other than using network
sockets.
Right.
So process can create a new message queue or can use an existing message queue which was created by
another process.
Right.
So if the message queue is already existing message queue, then the process can actually use the existing
message queue to send or receive the messages from the another process.
A message queue is identified by unique ID and no two message queue can have the same ID.
So within a Linux system, each message queue is assigned a unique ID, and this unique ID is actually
a string.
Right?
So no two message queues in the system can have the same unique ID at the same time.
Message queue resides and managed by the kernel and operating system.
So remember message queue is a kernel resource.
Kernel resource means a resource which exists inside the operating system inside the kernel.
Right.
So message queue resides and managed by the kernel operating system.
The processes only harness or make use of the message queue which resides in the operating system.
So message queue is actually a service that is provided by operating system to the userspace processes
for carrying out data exchange.
Right.
So we say that message is just one of the kernel resource.
So it's a kernel resource just like memory is one kernel resource message is another kernel resource.
So sending process A can post the data to the message queue and receiving process B reads the data from
the message queue.
As simple as that.
So the process which creates a new message queue is termed as owner or creator of the message queue.