当前位置:网站首页>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.
边栏推荐
- Electron application development best practices
- function two
- [相机配置] 海康相机丢包配置环境
- Win32控件------------显示系统使用的控件版本
- VBA实战(11) - 工作表(Sheet) 操作汇总
- The common problems in laptops, continuously updated
- day16_03集合
- Master-slave postition changes cannot be locked_Slave_IO_Running shows No_Slave_Sql_Running shows No---Mysql master-slave replication synchronization 002
- Oracle数据库:for update 和for update nowait的区别
- 收到人生第一笔五位数工资
猜你喜欢
随机推荐
实现下拉加载更多
如何快速打通镜像发布流程?
对话跨国消费品牌DPO:数据安全合规从何做起?8.11直播见!
snmp++编译错误问题解决方法
【size_t是无符号整数 (-1 > 10) -> 1】
MySQL备份与恢复
WUSTOJ:n个素数构成等差数列
Win32控件------------显示系统使用的控件版本
Qt 国际化翻译
Received your first five-figure salary
Restful WebServices 学习笔记
basic operator
Technology Sharing | How to simulate real usage scenarios?mock technology to help you
排序1:冒泡排序
【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题
集合与函数
[Halcon&定位] 解决Roi区域外的模板匹配成功
工作--今天的学习
小程序员的发展计划
深度学习--神经网络(基础讲解)