mutex信号灯文件权限

mutex信号灯文件权限

本文介绍了提升进程间named_mutex信号灯文件权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法创建共享内存,尝试打开或创建并设置不受限制的权限.

I am creating my shared memory using the below, trying either to open or create and setting unrestricted permissions.

void createMemory(const int numBytes)
{
    permissions perm;
    perm.set_unrestricted();

    segment.reset(new managed_shared_memory(open_or_create, memory_name, numBytes, 0, perm));

    // Exception throw on this line
    mutex.reset(new named_mutex(open_or_create, mutex_name, perm));

    cond_empty.reset(new named_condition(open_or_create, cv_name, perm));

    const ShmemAllocator alloc_inst(segment->get_segment_manager());
    vec = segment->find_or_construct<MyVector>(vector_name)(alloc_inst);
}

这将为named_mutex创建两个文件,即共享内存和(信号量?)文件:

This creates two files for named_mutex, the shared memory and the (semaphore?) file:

mutex_name
sem.mutex_name

第一个文件具有很好的权限,但是第二个文件是使用限制性权限创建的,从而阻止了第二个用户打开它.

The first file has permissions which are fine, but the second file is created with restrictive permissions, preventing the second user from opening it.

我已经在第一个用户的bashrc配置文件中配置了该用户,但这似乎无法解决问题.我还能如何强制该sem文件具有宽松的权限?

I have configured user in the bashrc profile of the first user, but that doesn't seem to fix the problem. How else can I force this sem file to have relaxed permissions?

推荐答案

此答案:

POSIX共享内存和信号灯权限集打开电话错误地

您可以通过编程将umask设置为零,然后恢复以前的umask值.

You set umask programatically to zero and then restore the previous umask value.

这篇关于提升进程间named_mutex信号灯文件权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:21