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:
 
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.





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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值