Inter-Process Communication Linux # # # message queue (message queue)

Message Queue is actually a queue in the operating system kernel created for us by the queue identifier key, each process can open this queue, each process can insert a node to the queue by the queue or Gets a node to complete the communication between different processes. Type of tissue with a user data block added to the queue, the process of acquiring the other data blocks from the queue, the message queue is sent with a block type; message queue is a full-duplex communication, readable write (data can be sent, you can also receive data). Life cycle with the kernel message queue, if the message queue is not released or not shut down the operating system, a message queue will always exist.

Message queue provided a method of transmitting a block of data from one process to another process. Each data block is considered to contain a type, the receiving process can independently receive containing different types of data structures. We can avoid synchronization and named pipes blocking problems by sending a message. However, the message queue as named pipes, each data block has a maximum length limit . Using Linux and macro MSGMAX MSGMNB to limit the maximum length of a message (System V standard) and a maximum length of the queue.

Message queues and anonymous pipe previously discussed, named pipes have a greater difference, mainly in the following two points:

  • Prior processes write messages to a message queue, a process does not need to wait for the arrival of the message in the queue, and the pipe and FIFO is the opposite, when the process write messages to each other, anonymous pipes and named pipes required is already open to read. 
  • Persistent IPC different. Anonymous pipes and named pipes are with the continuing process of , when the last anonymous pipes and named pipes shutdown occurs, the data pipes and named pipes are still anonymous will be discarded. With the message queue is persistent kernel , i.e., a process to write the message to a message queue, and then terminates, another process can open some time after the message queue is read. As long as the kernel does not re-start from the message queue is not deleted. That anonymous pipes and named pipes are synchronized to eliminate the queues are asynchronous.

Each message in the message queue typically has the following properties:

  • A represents an integer of priority;
  • Length of the data portion of the message;
  •  Message data itself;

Message queue represented in the core

 

Message queue (message queue) with the same division standard System V POSIX standard, detailed reference

Room # Linux # # System V IPC Standard & POSIX standard

Published 170 original articles · won praise 207 · Views 4.59 million +

Guess you like

Origin blog.csdn.net/xiaoting451292510/article/details/103731030