当前位置: 技术问答>linux和unix
关于IPC的简单问题
来源: 互联网 发布时间:2015-11-14
本文导语: 在看《UNIX 环境高级编程》中关于创建IPC用的三种结构有这么一段话: The identifier is an internal name for an IPC object . Cooperating processes need an external naming scheme to be able to rendezvous using the same IPC object. For...
在看《UNIX 环境高级编程》中关于创建IPC用的三种结构有这么一段话:
The identifier is an internal name for an IPC object . Cooperating processes need an external naming scheme to be able to rendezvous using the same IPC object. For this purpose, an IPC object is associated with a key that acts as an external name.
拿shmget来说,第一个参数就是key,函数成功就返回identifier。
还有下面一段:
1.The server can create a new IPC structure by specifying a key of IPC_PRIVATE and store the returned identifier somewhere (such as a file) for the client to obtain. The key IPC_PRIVATE guarantees that the server creates a new IPC structure. The disadvantage to this technique is that file system operations are required for the server to write the integer identifier to a file, and then for the clients to retrieve this identifier later.
我不明白的是为什么需要一个key作为外部名字?为什么不直接用identifier做,为什么要多一步key转换成identifier,就比如file descriptor,也不需要什么key啊?这里说client还是用server存到file里的identifier,那么这个key作为外部名字到底是什么意思?
The identifier is an internal name for an IPC object . Cooperating processes need an external naming scheme to be able to rendezvous using the same IPC object. For this purpose, an IPC object is associated with a key that acts as an external name.
拿shmget来说,第一个参数就是key,函数成功就返回identifier。
还有下面一段:
1.The server can create a new IPC structure by specifying a key of IPC_PRIVATE and store the returned identifier somewhere (such as a file) for the client to obtain. The key IPC_PRIVATE guarantees that the server creates a new IPC structure. The disadvantage to this technique is that file system operations are required for the server to write the integer identifier to a file, and then for the clients to retrieve this identifier later.
我不明白的是为什么需要一个key作为外部名字?为什么不直接用identifier做,为什么要多一步key转换成identifier,就比如file descriptor,也不需要什么key啊?这里说client还是用server存到file里的identifier,那么这个key作为外部名字到底是什么意思?
|
identifier,你怎么得到呢?你怎么保证是一致的呢?
我认为这是为了一致才搞的
我认为这是为了一致才搞的
|
identifier是内核(操作系统)相关的,key是应用相关的。相当于多了一层。如果没有key,则应用很难确定一个所有系统都可以唯一的identifier。key则不同,只要使用同一IPC设施的应用间约定就可以了。