当前位置:网站首页>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.
边栏推荐
- Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
- KMP& sunday
- How to quickly get through the mirror release process?
- Electron application development best practices
- 机器学习-逻辑回归(logistics regression)
- 源代码阅读器项目
- mongodb学习笔记
- MySQL索引的B+树到底有多高?
- 上传张最近做的E2用的xmms的界面的截图
- Redis 缓存主动更新策略
猜你喜欢
Redis + NodeJS 实现一个能处理海量数据的异步任务队列系统
Dialogue with the DPO of a multinational consumer brand: How to start with data security compliance?See you on 8.11 Live!
shell脚本实战(第2版)/人民邮电出版社 脚本1 在PATH中查找程序
机器学习--线性回归(Linear Regression)
蓄电池建模、分析与优化(Matlab代码实现)
机器学习-逻辑回归(logistics regression)
Transformer+Embedding+Self-Attention原理详解
深度学习--生成对抗网络(Generative Adversarial Nets)
笔记本电脑使用常见问题,持续更新
多行省略和选择器
随机推荐
1003 我要通过! (20 分)
3D printed this DuPont cable management artifact, and the desktop is no longer messy
Win32控件------------显示系统使用的控件版本
10000以内素数表(代码块)
使用cpolar远程连接群晖NAS(创建临时链接)
认识
stimulus.js 初体验
深度学习--神经网络(基础讲解)
SQL Server查询优化
好久没更新博客了
关于页面初始化
基本运算符
按键精灵之输出文本
1002 写出这个数 (20 分)
【size_t是无符号整数 (-1 > 10) -> 1】
学长告诉我,大厂MySQL都是通过SSH连接的
function two
Win32控件--------------------WM_DRAWITEM消息测试程序
MySQL和MyEclipse的数据库连接操作
Transformer+Embedding+Self-Attention原理详解