LINUX study notes 15 -- inter-process communication 4 Message Queue

Source: Internet
Author: User
A) essence: message linked list B) classification: 1. POSIX message queue: Port Operating System Interface 2. system V: as the kernel continues, it will be deleted only after kernel restart and manual deletion. Each message queue corresponds to a unique key value c) get the key value: Key_tftok (char * pathname,... a) essence: message linked list
 
B) Category:
 
1. POSIX message queue: Port operating system interfaces
 
2. System V: The System V will be deleted only after kernel restart and manual deletion. Each message queue corresponds to a unique key value
 
C) obtain the key value: Key_t ftok (char * pathname, char proj)
 
1. function: return the key value corresponding to the file name, essentially a file
 
2. # include , # Include
 
3. Pathname: file name
 
4. Proj: project name, not 0
 
D) get the description: int msgget (key_t key, int msgflg)
 
1. # include , # Include , # Include
 
2. Key: Key value, obtained by ftok
 
3. Msgflg: Flag
 
A) IPC_CREAT: if there is no message queue corresponding to the key value, create a new message queue.
 
B) IPC_EXCL: used together with IPC_CREAT. If an error is returned
 
C) IPC_NOWWAIT: if it cannot be met, it is not blocked.
 
4. return value: file descriptor msgid
 
E) send message: int msgsnd (int msqid, struct msgbuf * msgp, int msgsz, int msgflg)
 
1. # include , # Include , # Include
 
2. Msqid: message queue descriptor
 
3. Msgp: message storage structure:
 
A) struct msgbuf
 
B) {long mtype; message type, defined by yourself. one type can store multiple messages.
 
C) Char mtext [1];} first address of the message data
 
4. Msgsz: length
 
5. Msgflg: flag, IPC_NOWAIT: indicates whether to wait when the message queue does not have enough space to accommodate the message to be sent.
 
F) receive message: int msgrcv (int msqid, struct msgbuf * msgp, int msgsz, long msgtype, int msgflg)
 
1. function: read msgtype messages from the message queue, and the messages are no longer read.
 
2. Others are the same as above:
 
3. message length: length = sizeof (struct mymsgbuf)-sizeof (long)
Related Article

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.