semaphore - 如何使用 sem_open 为不同的用户访问相同的信号
问题描述
我使用 sem_open() 和 root 用户创建了全局信号量:
sem_t* sem = sem_open("ghMutex", O_CREAT, 0644, 1);
所以当我这样做时: ls -al /dev/shm/
-rw-r--r-- 1 根根 32 Jan 23 00:23 sem.ghMutex
现在我在 Linux 中有一个不同的用户(比如 User1),它再次调用相同的函数 sem_open 来创建信号量:
sem_t* sem = sem_open("ghMutex", O_CREAT, 0644, 1);
在最后一个函数调用中,我收到错误 EACCES(权限被拒绝),因为此名称的信号量已使用 root 用户创建。
我的问题:
1)如何为不同的用户创建具有相同名称的信号量?
2) 在 sem_open() 中对信号量进行命名约定以便多个用户可以访问的最佳实践是什么?
解决方案
You are setting readonly permissions for the other user.
0644
means:
- 6 (read and write) for the owner
- 4 (readonly) for other group users
- 4 (readonly) for anyone else
According to the man pages:
Both read and write permission should be granted to each class of user that will access the semaphore.
推荐阅读
- swift - 使用 xcuitest 获取状态复选框
- firebase - Firebase 阻止使用 Google 登录的电子邮件和密码登录连接
- python-3.x - 在计算平均值时使用 groupby 计算最小值和最大值
- java - 将不存在的元素从 String 添加到 ArrayList
- stm32 - 在两次传输之间禁用 STM32H7 上的 SPI 外设?
- svn - 加载修订更改 svn:author
- c# - 在使用它的应用程序关闭后持有 WCF TCP 端口的系统进程
- android - OnverificationCompleted() 被调用但没有收到任何 otp
- python - 导入另一个python文件时Django runserver没有运行
- vb.net - Vb-net 在准备表格时隐藏布局