Kernel structure and msgget, msgctl functions of Linux System V message queues

Source: Internet
Author: User
Tags message queue

First, Message Queuing

1. Message Queuing provides a way to send a piece of data from one process to another

2. Each block of data is considered to have a type, and the receiver process receives a data block that can have a different type value

3. Message Queuing differs from pipelines in that message queues are based on messages, and pipelines are based on byte throttling, and Message Queuing reads are not necessarily first-in-first-out.

4, Message Queuing also has the same shortage of pipelines, is that the maximum length of each message is capped (Msgmax), the total number of bytes per message queue is capped (MSGMNB), and the total number of message queues on the system is also capped (Msgmni), which can be viewed with three parameters:

simba@ubuntu:~/documents/code/linux_programming/unp/system_v$ Cat/proc/sys/kernel/msgmax

8192

simba@ubuntu:~/documents/code/linux_programming/unp/system_v$ CAT/PROC/SYS/KERNEL/MSGMNB

16384

simba@ubuntu:~/documents/code/linux_programming/unp/system_v$ Cat/proc/sys/kernel/msgmni

1711

Second, the IPC object data structure

The kernel maintains a data structure for each IPC object

struct Ipc_perm {

key_t __key; /* Key supplied to Xxxget (2) * *

uid_t uid; /* Effective UID of owner/*

gid_t GID; /* Effective GID of owner/*

uid_t cuid; /* Effective UID of creator * *

gid_t Cgid; /* Effective GID Creator * *

unsigned short mode; * Permissions * *

unsigned short __seq; /* Sequence Number * *

};

Message Queuing, shared memory, and semaphores all have such a common data structure.

Third, message queue structure

struct Msqid_ds {

struct Ipc_perm msg_perm; /* Ownership and Permissions * *

time_t Msg_stime; /* Time of Last msgsnd (2) * *

time_t Msg_rtime; /* Time of Last MSGRCV (2) * *

time_t Msg_ctime; /* Time of last change * *

unsigned long __msg_cbytes; /* Current number of bytes in

Queue (nonstandard) * *

Msgqnum_t Msg_qnum; /* Current number of messages

In Queue * *

Msglen_t msg_qbytes; * Maximum Number of bytes

Allowed in Queue * *

pid_t Msg_lspid; /* PID of Last MSGSND (2) * *

pid_t Msg_lrpid; /* PID of Last MSGRCV (2) * *

};

You can see that the first entry is the IPC structure, which is common, followed by the members that are private to Message Queuing.

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.