当前位置:网站首页>UNIX Environment Programming Chapter 15 15.6 XSI IPC
UNIX Environment Programming Chapter 15 15.6 XSI IPC
2022-08-09 10:29:00 【Mary Soda Meatloaf】
15.6.1 Identifiers and keys
IPC structures (message queues, semaphores, or shared memory segments) in each kernel are referenced by a non-negative integer identifier.When an IPC structure is created and then deleted, the identifiers associated with the structure are incremented by 1 until the maximum positive integer value is reached, and then rolled back to 0.
Each IPC object is associated with a key that is used as the object's external name.
A key should be specified whenever an IPC structure is created.The data type of this key is the basic system data type key_t, which is usually defined as a long in the header file.This key is programmed with an identifier by the kernel.This key is transformed into an identifier by the kernel.
There are several ways to bring client and server processes together on the same IPC structure.
- The server process can specify the key IPC_PRIVATE to create a new IPC structure and store the returned identifier somewhere for the client process to access.The IPC_PRIVATE key can also be used for parent-child relationships.The parent process specifies IPC_PRIVATE to create a new IPC structure, and the returned identifier can be used by the child process after fork.
- A key recognized by both client and server processes can be included in a common header file.The server process then assigns this key to create a new IPC structure.
- The client process and the server process identify a pathname and project ID, and then call the function ftok to turn these two values into a key.
The only service provided by ftok is to generate a key from a pathname and a project ID.
#include key_t ftok(const char* path,int id);//Success returns the key, failure returns -1
The path parameter must refer to an existing file. When generating the key, only the lower 8 bits of the id parameter are used.
The keys created by a fork are usually formed by taking the partial st_dev and st_ino fields in its stat structure by the given pathname, and then combining them with the project ID.If the two pathnames refer to two different files, then ftok will usually return different keys for the two pathnames.But because the inode number and key are usually stored in a long integer, information may be lost when the key is created.This means that for two pathnames to different files, it is possible to produce the same key if the same item ID is used.
15.6.2 Permission structure
XSI IPC associates an ipc_perm structure with each IPC structure.
When creating an IPC structure, assign initial values to all fields.Later, you can call msgctl, semctl, shmctl to modify the uid, gid and mode fields.In order to modify these values, the calling process must be the creator or superuser of the IPC structure.
边栏推荐
- 【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题
- Unix Environment Programming Chapter 14 14.4 I/O Multiplexing
- Technology Sharing | Sending Requests Using cURL
- mongodb学习笔记
- 1003 我要通过! (20 分)
- antd的Table列选择、列拓展
- 京东物流与五菱将开发联名版定制产品
- How to quickly get through the mirror release process?
- Database connection operations for MySQL and MyEclipse
- OneNote 教程,如何在 OneNote 中搜索和查找笔记?
猜你喜欢
[贴装专题] 基于多目视觉的手眼标定
编解码(seq2seq)+注意机制(attention) 详细讲解
The common problems in laptops, continuously updated
MySQL索引的B+树到底有多高?
Solve the ali cloud oss - the original 】 【 exe double-click response can't open, to provide a solution
Transformer+Embedding+Self-Attention原理详解
多行省略和选择器
深度学习--循环神经网络(Recurrent Neural Network)
机器学习--朴素贝叶斯(Naive Bayes)
开源SPL,WebService/Restful广泛应用于程序间通讯,如微服务、数据交换、公共或私有的数据服务等。
随机推荐
conditional control statement
自启服务mock联调跨域问题
1005 继续(3n+1)猜想 (25 分)
深度学习--循环神经网络(Recurrent Neural Network)
常用语言图表库总结
Loop nesting and basic operations on lists
浅析JWT安全问题
The GNU Privacy Guard
Win32控件--------------------WM_DRAWITEM消息测试程序
stimulus.js 初体验
壁纸
函数二
机器学习-逻辑回归(logistics regression)
1002 写出这个数 (20 分)
Redis cache update strategy actively
技术分享 | 使用 cURL 发送请求
Attentional Feature Fusion
收到人生第一笔五位数工资
RTP
MySQL和MyEclipse的数据库连接操作