当前位置: 技术问答>linux和unix
POSIX:有名信号量 和SYStem V的信号量 你用哪个?
来源: 互联网 发布时间:2017-03-15
本文导语: 如题,我有点不太清楚就是,是不是Unix是不是这两种信号量都有,还有这两个信号量感觉可以互相取代,最后的问题就是POSIX命名信号量 在不同进程之间是不是通过信号量的文件名进行锁定的,也就是通过 sem_open(...
如题,我有点不太清楚就是,是不是Unix是不是这两种信号量都有,还有这两个信号量感觉可以互相取代,最后的问题就是POSIX命名信号量 在不同进程之间是不是通过信号量的文件名进行锁定的,也就是通过 sem_open(文件名),依靠这个文件名来锁定不同的进程? 而SYSTEM V的信号量 是通过 key_t来锁定的? 请教了
|
实际上SYSTEM V IPC应用更为广泛,使用也更为方便。
1. sem_open确定第一个参数name就让人大费周折,由于没有确定信号量名称的命名空间能否与文件系统相关,而文件系统就会涉及权限问题。
比如Solaris下sem_open("/sem1")能成功,在Digital Unix下却失败,除非有根目录(/)的写权限。
SYSTEM V IPC 通过 key_t 来区分,使用ftok,只要对文件系统有适当的访问权限,就能方便的命名IPC。
sem_t * sem_open (const char *name, int oflag, mode_t mode, unsigned value);
The name argument points to a string naming a semaphore object. It is unspecified whether the name appears in the file system and is visible to functions that take pathnames as arguments. The name argument conforms to the construction rules for a pathname. If name begins with the slash character, then processes calling sem_open() with the same value of name will refer to the same semaphore object, as long as that name has not been removed. If name does not begin with the slash character, the effect is implementation-dependent. The interpretation of slash characters other than the leading slash character in name is implementation-dependent.
2. sem_wait成功后获取信号灯后,进程如果意外终止,将无法释放信号灯。
SYSTEM V IPC 提供 SEM_UNDO选项用于此目的
|
POSIX是标准,SYSTEM v不是,但是实际上大部分的系统都支持2者,从时代性上讲,posix是后来者,考虑的问题和兼容性更多一些。system v是比较旧的IPC标准。
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。