当前位置:网站首页>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.
边栏推荐
- [相机配置] 海康相机丢包配置环境
- 壁纸
- Win32控件------------显示系统使用的控件版本
- Cpolar内网穿透的面板功能介绍
- 蓄电池建模、分析与优化(Matlab代码实现)
- OpenGL 2.0编程例子
- Unix Environment Programming Chapter 14 14.4 I/O Multiplexing
- Oracle数据库:for update 和for update nowait的区别
- 3D printed this DuPont cable management artifact, and the desktop is no longer messy
- unix环境编程 第十五章 15.8信号量
猜你喜欢
随机推荐
公里周日
markdown转ipynb--利用包notedown
通过Doc在MySQL数据库中建表
【MySQL】mysql因为字符集导致left join出现Using join buffer (Block Nested Loop)
小程序员的发展计划
【size_t是无符号整数 (-1 > 10) -> 1】
OpenGL ES2.0编程三部曲(转载自MyArrow)
snmp++编译错误问题解决方法
1: bubble sort
basic operator
浅析JWT安全问题
BERT预训练模型(Bidirectional Encoder Representations from Transformers)-原理详解
tuple dictionary collection
排序1:冒泡排序
虚拟列表key复用问题
1002 写出这个数 (20 分)
【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
3D printed this DuPont cable management artifact, and the desktop is no longer messy
LM小型可编程控制器软件(基于CoDeSys)笔记二十六:plc的数据存储区(模拟量输入通道部分)
TELNET协议相关RFC