正在设置由boost创建的共享内存的权限
Setting permission for shared memory created by boost
我们打开了一个由另一个进程(如)创建的boost共享内存
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "SharedMem");
但是,如果创建共享内存的进程是根用户,那么读取它的进程(如果是普通用户)将失败,原因如下:
terminate called after throwing an instance of 'boost::interprocess::interprocess_exception'
what(): Permission denied
我该怎么做才能避免这种情况?就是允许所有人共享内存?
如果查看shared_memory构造函数,它会获取一个权限对象。boost::interprocess::permissions::set_unrestricted
可能就是您想要的
void set_unrestricted();
//Sets permissions to unrestricted access:
// A null DACL for windows or 0666 for UNIX.
据此,它被添加到1.45版本
下面是一个示例代码片段,用于在创建期间授予共享内存不受限制的权限
boost::interprocess::permissions unrestricted_permissions;
unrestricted_permissions.set_unrestricted();
shared_mem = new managed_shared_memory(open_or_create, name.c_str(), size, 0, unrestricted_permissions);
相关文章:
- 使用Boost Interprocess创建托管共享内存需要很长时间
- 字符串共享内存映射的向量
- CUDA 使用共享内存平铺 3D 卷积实现
- 共享内存:MapViewOfFile 返回错误 5
- 如何在多写入器情况下对文件支持的共享内存中的大页面出错
- 有没有办法列出所有共享内存对象的名称?
- 共享内存的升压容器是否实现锁定?
- 共享内存中的健壮互斥锁不是那么健壮
- 使用IPC/共享内存将Integer数组从C++传递到Python
- 共享内存和性能
- 在这种特殊情况下,我是否需要在共享内存中使用原子类型
- 是否可以在专用内存空间中分配一个为提升管理共享内存而创建的对象
- fork(),在C中共享内存和指针
- 访问共享内存而不使用易失性、std::atomic、信号量、互斥锁和自旋锁
- 提升进程间共享内存open_or_create每次都会引发异常
- 通过 mmap-ed 共享内存传递可变长度 C 字符串
- 越界访问 CUDA 共享内存
- 在共享内存中插入映射映射时出现编译器错误
- 矩阵矢量产品 CUDA 通过平铺和共享内存提高性能
- 如何更改在 c++ 中使用提升库创建的共享内存的路径