[Home] [Credit Search] [Category Browser] [Staff Roll Call] | The LINUX.COM Article Archive |
Originally Published: Friday, 24 August 2001 | Author: Subhasish Ghosh |
Published to: develop_articles/Development Articles | Page: 4/5 - [Printable] |
Understanding Linux Kernel Inter-process Communication: Pipes, FIFO & IPC (Part 2)
The Linux kernel is a thing of great beauty and learning to understand and appreciate its facets and edges is a worthy and noble pursuit. Take our hand as Linux.com offers this second part of Subhasish Ghosh's look at Inter-Process Communication in the Linux Kernel. Together we will find the grok, sooner or later.
|
<< Page 4 of 5 >> | |||||||||||||||||||||||||||||||||||||||||||
IPC MessagesAnother IPC resource, which processes can use to communicate with each other is IPC Messages. Each message generated by a process is sent to an "IPC Message Queue", where it stays until another process reads it. So, the question now is: What is this so-called "IPC message" made up of? A message is made up of a fixed-size "header" and a variable-length "text". Thus, it can be labeled with an integer value (the message type) which allows a process to selectively retrieve messages from the message queue. Readers must note that: A message queue is implemented in reality by means of a linked list. Once a process has read a message from an IPC message queue, the Kernel destroys it. Thus, this proves the well-known fact: Only one process can receive a given message. So, let's now see what functions a process needs to invoke in order to send a message and retrieve one. For sending a message, a process invokes the
For retrieving a message, a process invokes the
Now, the integer t can take any one of these three values: either t is null, t is (+ve) or t is (-ve). If the value of t is null, the first message in the queue is returned. If t is positive, the first message in the queue with its type equal to t is returned. Finally, if t is negative, the function returns the first message whose message type is the lowest value less than or equal to the absolute value of t. Till this, it's just fine. Beyond this, make sure you get ready for a real roller-coaster ride. Why? Read on. Now, let's talk a little about the data structures associated
with IPC messages. There exists an "IPC Message Queue
Descriptor", whose address is very important since it is
used for many critical purposes. Understanding what this
"IPC Message Queue Descriptor" is, is where our
roller-coaster ride begins. Make sure you hold on tight! The
"IPC Message Queue Descriptor" is a
Let's now look at a code snippet illustrating an IPC Message queue in action.
Now, that we have seen what an IPC message is and in what way it relates to an IPC Message Queue, the most important data structure in action, along with a code snippet illustrating a message queue, its now time for all of us to move on to the next and last section of this article, IPC Shared Memory.
| |||||||||||||||||||||||||||||||||||||||||||
<< Page 4 of 5 >> |