当前位置:网站首页>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.
边栏推荐
- 10000以内素数表(代码块)
- Cpolar内网穿透的面板功能介绍
- 想了解API接口,这一篇就够了
- day16_03集合
- Redis 缓存主动更新策略
- By asking where the variables are stored, the shepherd boy laughed and said to use pointers, Go lang1.18 introductory refining tutorial, from Bai Ding to Hongru, the use of go lang type pointers (Poin
- 编程技术提升
- UNIX Environment Programming Chapter 15 15.5FIFO
- 使用.NET简单实现一个Redis的高性能克隆版(四、五)
- [项目配置] 配置Qt函数库和ui界面库的封装并调用的项目
猜你喜欢
[贴装专题] 贴装流程中涉及到的位置关系计算
[贴装专题] 视觉贴装平台与贴装流程介绍
3D打印了这个杜邦线理线神器,从此桌面再也不乱了
多行省略和选择器
BERT预训练模型(Bidirectional Encoder Representations from Transformers)-原理详解
Qt 国际化翻译
Loop nesting and basic operations on lists
深度学习--生成对抗网络(Generative Adversarial Nets)
[Error record] Solve the problem that ASRock J3455-ITX cannot be turned on without a monitor plugged in
想了解API接口,这一篇就够了
随机推荐
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
深度学习--自编码器(AutoEncoder)
元组 字典 集合
使用.NET简单实现一个Redis的高性能克隆版(四、五)
unix环境编程 第十五章 15.9 共享存储
按键精灵之输出文本
SQL Server查询优化
好久没上博客了,好长时间没有进展了
antd的Table列选择、列拓展
集合与函数
unix环境编程 第十四章 14.4 I/O多路转接
笔记本电脑使用常见问题,持续更新
snmp++编译错误问题解决方法
学长告诉我,大厂MySQL都是通过SSH连接的
强化学习 (Reinforcement Learning)
MySQL执行过程及执行顺序
【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
一天半的结果——xmms on E2
Pyhton实战汇总篇
hover内部指定子类的样式