当前位置:网站首页>Unix Environment Programming Chapter 15 15.7 Message Queuing
Unix Environment Programming Chapter 15 15.7 Message Queuing
2022-08-09 10:29:00 【Mary Soda Meatloaf】
A message queue is a linked list of messages, stored in the kernel, identified by a message queue identifier, or queue ID for short.
msgget is used to create a new queue or open an existing queue.
#include int msgget(key_t key,int flag);//Successfully returns the message queue ID, failure returns -1 When creating a new queue, initialize the following members of the msqid_ds structure:
- The ipc_perm structure is initialized as described in Section 15.6.2.The mode member in this structure is set according to the corresponding permission bit in flag.
- msg_qnum, msg_lsqid, msg_lrpid, msg_stime and msg_rtime are all set to 0.
- msg_ctime is set to the current time.
- msg_qbytes is set to the system limit value.
msgsnd adds a new message to the end of the queue.
msgrcv is used to get messages from the queue.
The msgctl function performs various operations on the queue.It and two other functions related to semaphores and shared storage are XSI IPC ioctl-like functions.
#include int msgctl(int msqid,int cmd,struct msqid_ds *buf);//successful return 0, error return -1 The cmd parameter specifies the command to be executed on the queue specified by msqid.
Call msgsnd to put data in the message queue
#include int msgsnd(int msqid,const void *ptr,size_t nbytes,int flag);//Success returns 0, failure returns -1 The ptr parameter points to a long integer containing the positive integer message type, followed by the message data.
When msgsnd returns successfully, the msqid_ds structure related to the message queue will be updated accordingly, indicating the calling process ID, the calling time and the new message in the message queue.
msgrcv fetches messages from the queue.
#include ssize_t msgrcv(int msqid,void *ptr,size_t nbytes,long type,int flag);//Successfully returns the length of the message data part, error returns -1 The ptr parameter points to a long integer followed by a buffer where the actual message data is stored.nbytes specifies the length of the data buffer.If the length of the returned message is greater than nbytes, and the MSG_NOERROR bit is set in the flag, the message will be truncated.If this flag is not set and the message is too long, E2BIG is returned on error.
The parameter type specifies which kind of message is desired.
type==0, returns the first message in the queue.
type>0 returns the first message of type type in the queue.
type<0 returns the message whose message type value is less than or equal to the absolute value of type in the queue. If there are several such messages, the message with the smallest type value is selected.
边栏推荐
猜你喜欢

Loop nesting and basic operations on lists

使用cpolar远程连接群晖NAS(创建临时链接)

对话跨国消费品牌DPO:数据安全合规从何做起?8.11直播见!
上传张最近做的E2用的xmms的界面的截图

Cpolar内网穿透的面板功能介绍

编解码(seq2seq)+注意机制(attention) 详细讲解

Dialogue with the DPO of a multinational consumer brand: How to start with data security compliance?See you on 8.11 Live!

笔记本电脑使用常见问题,持续更新

antd表单
![[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in](/img/a9/d6aba07e6a4e1536cd10d91f274b2e.jpg)
[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in
随机推荐
RTP
1005 继续(3n+1)猜想 (25 分)
Technology Sharing | Sending Requests Using cURL
Win32控件------------显示系统使用的控件版本
xmms的均衡器试验成功 音效相当不错 比rockbox可能还要好
Redis cache update strategy actively
条件控制语句
[贴装专题] 贴装流程中涉及到的位置关系计算
BERT预训练模型(Bidirectional Encoder Representations from Transformers)-原理详解
UNIX Environment Programming Chapter 15 15.5FIFO
一天半的结果——xmms on E2
Oracle数据库:for update 和for update nowait的区别
Qt 国际化翻译
【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
MySQL和MyEclipse的数据库连接操作
函数二
[贴装专题] 视觉贴装平台与贴装流程介绍
Received your first five-figure salary
常用语言图表库总结
按键精灵之输出文本