POSIX Message Queue

Source: Internet
Author: User

Every time you read a book, you will see new knowledge.

I. Overview of IPC preface:
1. The name is the means by which the customer and the server are connected to each other to exchange messages.
2. IPC common attributes: path name, flag specified when it is enabled or created, and access permission
3. note: Solaris requires a slash header path/, for example,/queue.1234 => /. mqdqueue.123,/tmp /. mqlqueue.1234/tmp /. mqpqueue.1234, date lock p... permission
On other Linux/Unix systems, create by path name,/queue.1234 =>/queue.1234. In this way, the root directory permission is required. Therefore, we need to do a good job of compatibility processing (definition macros, etc.), because not all software is for root users only.
4. POSIX method for creating and enabling IPC: mq_open (which can be enabled in any mode) and sem_open (open mode is not specified, because operations on semaphores must be read/written ), shm_open (cannot be opened in write-only mode)
(Open flag) o_creat, o_excl (an error is returned if an error exists), o_nonblock (non-blocking), and o_tunc (if the memory share area already exists, this flag will make the object length cut to 0), s_irusr, s_iwusr, s_irgrp, s_iwgrp, s_iroth, s_iwoth (permission bit)
, O_rdonly, o_wronly, o_rdwr
The path names are used for the posixipc, message queue, semaphore, and shared memory of the 5.3 types. The permission setting for open starts with s_xxx, which is the same as the permission test for open files.
6. systemvipc, key_t, ftok, and IPC key value. Files whose path names are used to generate key values cannot be repeatedly created and deleted by the server during the survival of the server. They must be stable. Because each creation changes the index node, ftok is created differently for the next caller.
----------------------
7. ipc_perm structure: Each IPC object (message queue, Memory Sharing, semaphore) maintains an information structure: (defined in sys/IPC. h) -------> systemv is also defined here.
Struct ipc_perm {
Uid_t uid; gid_t GID;
Uid_t cuid; gid_t cgid; mode_t mode;
Ulong_t seq; ket_t key;
};
8. IPCS ipcrm
9. kernel restrictions: 1. the configuration file 2. Use the sysconfig command to modify it. The kernel is usually limited because the configuration is low in the previous development and definition, which is not as good as the current level.
The biggest problem with using systemvipc is that most implementations impose human kernel restrictions on the size of these objects.

II. Pipe: pipe popen close witepid pclose mkfifo fork

3. POSIX Message Queue
1. A Message Queue can be considered as a message linked list. If you have sufficient permissions
2. Difference Between POSIX and systemv
1. POSIX always returns the earliest message with the highest priority, and systemv can specify any priority message.
2. POSIX allows a signal or thread to be generated when messages are placed in an empty queue, while systemv does not.
3. Each message attribute: 1. type, length of the Data part, and data itself
4. Each queue has its own linked list header message: there are two attributes of the queue, 1, the maximum Message Size 2. the maximum number of messages
5. Attribute struct mq_attr {flag blocking flag, maxmsg, msgsize, curmsgs), set the maxmsg, msgsize, and
6. Priority: smaller than macro: mq_prio_max,
7. mq_notify function, sending signals or starting threads
8. The execution of the signal registration function (which is executed by the kernel and switched to the kernel state) will block the execution of the main thread. The main thread will continue to execute the function only when it knows that the function is returned. In addition, only the "Asynchronous signal security function" can be called in the registration function ".
9. Use of POSIX real-time signals: queuing will not be lost; priority, small first; can carry more information.

Note: New applications should consider using POSIX message queues. POSIX message queues lack the ability to read messages with a specified priority from queues.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.