【问题标题】:shm_open() function no such file or directoryshm_open() 函数没有这样的文件或目录
【发布时间】:2013-09-24 15:33:15
【问题描述】:

我正在尝试使用 shm_open() 创建一个新的共享内存文件,但我得到 errno 2(没有这样的文件或目录)。

shm_open ("/DIAG_public", O_CREAT | O_RDWR, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH);

我已尝试创建自己的独立应用程序以使用相同的名称和选项运行 shm_open,而这成功...

因此检查 /dev/shm 是否具有 drwxrwxrwt 权限,并且运行实际代码的进程是否具有 -rwxrwxrwx 权限。

另外,mount | grep shm 返回:

tmpfs on /dev/shm type tmpfs (rw)

我没有想法...关于可能出错的任何建议?

谢谢。

【问题讨论】:

  • 我假设您的意思是 程序 具有 rwxrwxrwx 权限 - 进程没有权限。顺便说一句,0777 是一个非常糟糕程序拥有的权限集。
  • 嗨,是的,抱歉,程序未处理。我无法控制授予该程序的权限:P,但我相信它是 0777,因为它实际上是为外部硬件编写的(我现在正试图在 linux 上运行以加快测试速度)。
  • 有人找到解决方案了吗?我也有同样的问题!
  • 尝试在strace 下运行您的程序,看看哪个系统调用失败以及使用哪些参数。
  • 也许你应该展示你的代码片段

标签: c posix


【解决方案1】:

确保您确实通过了 O_CREAT。只有这似乎给出了这个错误。

手册页说 ENOENT 仅在两种情况下返回。不过,对于 shm_open,只有第一个似乎是有效的。

man shm_open
ERRORS
       On failure, errno is set to indicate the cause of the error.  Values which may appear in errno include the following:

    ...

        ENOENT An attempt was made to shm_open() a name that did not exist, and O_CREAT was not specified.

        ENOENT An attempt was to made to shm_unlink() a name that does not exist.

【讨论】:

    猜你喜欢
    • 2017-04-18
    • 2021-06-24
    • 2012-08-05
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多