【问题标题】:Setting permission for shared memory created by boost设置boost创建的共享内存的权限
【发布时间】:2012-02-04 05:52:57
【问题描述】:

我们打开一个由另一个类似这样的进程创建的 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

我应该怎么做才能避免这种情况?就是把共享内存的权限给所有人?

【问题讨论】:

    标签: c++ permissions boost-interprocess


    【解决方案1】:

    如果您查看 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版本添加的

    【讨论】:

    • 它是在什么版本中实现的?
    • 有没有将它包含在 1.42 中?它是 ubuntu 存储库可用的版本,我无权通过安装二进制文件手动更新它。
    猜你喜欢
    • 2018-10-21
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多