我是靠谱客的博主 缓慢信封,最近开发中收集的这篇文章主要介绍sem_open中信号量命名,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

问题:
sem_open will failed with "No such file or directory"
 
解释1:
这是由于在Linux内核中,创建信号量的默认路径是/dev/shm。当你要创建一个信号量/tmp/mysem时,实际上是创建了一个/dev/shm /sem.tmp/mysem,而这里由于/dev/shm/tmp目录根本就不存在,所以会出错。
解决方法:
    *直接写信号量文件的名字或宏定义不带路径,将会创建在/dev/shm中:sem_open("mysem", ...) 
 
解释2:
http://listman.redhat.com/archives/phil-list/2003-January/msg00113.html
 
If define name as "/tmp/xxxx", and invoke sem_open(name, flag...), sem_open will failed with "No such file or directory". 
Looked into the code sem_open.c, the reason is that the name ("/tmp/xxxx")will map to /dev/shm/sem.tmp/xxxx, but sem.tmp directory is not there, so there will be an error.
I think in sem_open.c, it maybe needs a check of whether name has more slash characters other than the leading slash character.
If it has, mkdir the related directory before rename operation (sem_open.c:234), such as the following:
  1. tmpname = strrchr(finalname,'/');// get the file name without directory
  2. strncpy(pathname, finalname, strlen(finalname)- strlen(tmpname));// get the directory path
  3. mkdir(pathname,0777)
To the POSIX std, it says the interpretation of slash characters other than the leading slash character in name is implementaion defined. I think it will be more friendly to allow the user using a name with directory.



来自为知笔记(Wiz)



转载于:https://www.cnblogs.com/fengkang1008/p/4733193.html

最后

以上就是缓慢信封为你收集整理的sem_open中信号量命名的全部内容,希望文章能够帮你解决sem_open中信号量命名所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(37)

评论列表共有 0 条评论

立即
投稿
返回
顶部