WEBVTT

00:05.350 --> 00:07.040
So welcome back, guys.

00:07.060 --> 00:12.010
Next IPC technique that we will going to learn in this module is message queue.

00:12.640 --> 00:17.230
So in this module we will going to learn about the concepts of message queue.

00:17.260 --> 00:24.850
As an IPC, we will learn about message queue concepts, we will learn about the APIs that is provided

00:24.850 --> 00:28.740
by Linux operating system for message queue management.

00:28.750 --> 00:35.080
And then we will discuss some of the design aspects regarding how message queue should be used.

00:35.170 --> 00:38.410
And then we will wind up this module with a code walk.

00:38.920 --> 00:44.650
That is, we will going to discuss the steps to implement message queue based inter-process communication

00:44.650 --> 00:46.240
between two processes.

00:47.630 --> 00:53.720
So you can see in this diagram, this diagram essentially captures the functioning of a message queue.

00:53.750 --> 00:58.780
That is how message queue can be used to implement IPC between two processes.

00:58.790 --> 01:04.550
So we have here a process, a which is actually a sender process and is running on a Linux machine.

01:04.550 --> 01:10.160
And we have a process B which is a receiver process and is running on the same Linux machine.

01:10.430 --> 01:17.690
So you can see that between process A and process B, the channel of communication is a message queue.

01:18.200 --> 01:20.300
The process A is a sender process.

01:20.300 --> 01:26.390
That is, it can enqueue the message in the message queue and the messages are then delivered to the

01:26.390 --> 01:26.780
process.

01:26.810 --> 01:31.400
B In the same sequence in which the message was encoded by the process.

01:31.400 --> 01:38.630
A So the process of removing the message from the message queue at the other end is called DQ of a message

01:38.630 --> 01:41.930
and DQ operation is done by the receiver process.

01:41.930 --> 01:47.940
So you can see that message queue is actually a communication channel between the process A and process

01:47.970 --> 01:55.020
B, So Linux or Unix based operating systems provide another mechanism for carrying out Inter-process

01:55.020 --> 01:55.920
communication.

01:55.920 --> 01:58.620
And this mechanism is called message queue.

01:59.920 --> 02:04.690
Processes that is running on the same machine can exchange any data using message queue.

02:04.720 --> 02:11.080
So remember, message queue is a mechanism to implement IPC between processes which are running on the

02:11.080 --> 02:12.010
same machine.

02:12.040 --> 02:17.740
If the processes are running on different machines means there is no other way other than using network

02:17.740 --> 02:18.580
sockets.

02:18.910 --> 02:19.600
Right.

02:19.960 --> 02:26.230
So process can create a new message queue or can use an existing message queue which was created by

02:26.230 --> 02:27.310
another process.

02:27.760 --> 02:28.540
Right.

02:28.810 --> 02:35.320
So if the message queue is already existing message queue, then the process can actually use the existing

02:35.320 --> 02:39.730
message queue to send or receive the messages from the another process.

02:40.300 --> 02:45.730
A message queue is identified by unique ID and no two message queue can have the same ID.

02:46.060 --> 02:53.710
So within a Linux system, each message queue is assigned a unique ID, and this unique ID is actually

02:53.710 --> 02:54.880
a string.

02:56.530 --> 02:57.310
Right?

02:57.340 --> 03:02.000
So no two message queues in the system can have the same unique ID at the same time.

03:02.960 --> 03:06.980
Message queue resides and managed by the kernel and operating system.

03:06.980 --> 03:10.070
So remember message queue is a kernel resource.

03:10.070 --> 03:16.640
Kernel resource means a resource which exists inside the operating system inside the kernel.

03:16.760 --> 03:17.420
Right.

03:17.420 --> 03:21.530
So message queue resides and managed by the kernel operating system.

03:21.530 --> 03:28.430
The processes only harness or make use of the message queue which resides in the operating system.

03:28.430 --> 03:34.700
So message queue is actually a service that is provided by operating system to the userspace processes

03:34.700 --> 03:36.830
for carrying out data exchange.

03:37.930 --> 03:38.500
Right.

03:38.500 --> 03:42.760
So we say that message is just one of the kernel resource.

03:44.630 --> 03:52.100
So it's a kernel resource just like memory is one kernel resource message is another kernel resource.

03:52.490 --> 03:58.940
So sending process A can post the data to the message queue and receiving process B reads the data from

03:58.940 --> 03:59.910
the message queue.

03:59.930 --> 04:01.490
As simple as that.

04:02.480 --> 04:09.080
So the process which creates a new message queue is termed as owner or creator of the message queue.
