我们打开一个由另一个进程创建的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
我应该做些什么来避免这种情况?也就是说,将共享内存的权限授予所有人?
发布于 2012-01-06 22:01:40
如果您查看shared_memory constructor,它接受一个permissions对象。boost::interprocess::permissions::set_unrestricted
可能就是您要查找的内容
void set_unrestricted();
//Sets permissions to unrestricted access:
// A null DACL for windows or 0666 for UNIX.
根据this的说法,它是在1.45版本中添加的
发布于 2022-02-09 02:22:41
下面是示例代码片段,用于在创建期间授予对共享内存的无限制权限
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);
https://stackoverflow.com/questions/8758896
复制相似问题