设置boost创建的共享内存的权限
我们打开一个由另一个进程创建的增强共享内存,如下所示
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "SharedMem");
内存的进程是 root 用户,那么读取它的进程(如果是普通用户)将失败,原因如下:
terminate called after throwing an instance of 'boost::interprocess::interprocess_exception'
what(): Permission denied
但是,如果创建共享 我该怎么做才能避免这种情况?也就是给所有人共享内存的权限?
We open a boost shared memory that was created by another process like this
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "SharedMem");
But if the process that created the shared memory was a root user, then the process reading it, if it was a normal user, will fail with the reason as:
terminate called after throwing an instance of 'boost::interprocess::interprocess_exception'
what(): Permission denied
What should i do to avoid this? that is to give permission to the shared memory to all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您查看 shared_memory 构造函数,它需要一个权限对象。
boost::interprocess::permissions::set_unrestricted
可能是您正在寻找的根据 这个,是1.45版本添加的
If you look at the shared_memory constructor, it takes a permissions object.
boost::interprocess::permissions::set_unrestricted
is probably what you are looking forAccording to this, it was added in 1.45 version
下面是一个示例代码片段,用于在创建期间授予对共享内存的不受限制的权限
Below is a sample code snippet, to grant unrestricted permission to shared memory during creation