shm_open()函数无此文件或目录 [英] shm_open() function no such file or directory
问题描述
我正在尝试使用shm_open()创建一个新的共享内存文件,但是却出现了errno 2(无此文件或目录).
I'm trying to create a new shared memory file using shm_open(), but I'm getting errno 2 (No such file or directory).
shm_open ("/DIAG_public", O_CREAT | O_RDWR, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH);
我尝试创建自己的独立应用程序,以使用相同的名称和选项运行shm_open,并且此 成功...
I've tried creating my own standalone app to run shm_open with the same name and options, and this is successful...
因此请检查/dev/shm是否具有drwxrwxrwt
权限,以及运行实际代码的进程是否具有-rwxrwxrwx
权限.
So checked that /dev/shm has drwxrwxrwt
permissions and that the process running the actual code has -rwxrwxrwx
permissions.
此外,mount | grep shm
返回:
tmpfs on /dev/shm type tmpfs (rw)
我没有主意...关于可能出什么问题的任何建议?
I'm out of ideas... any suggestions on what could be going wrong?
谢谢.
推荐答案
请确保您实际上正在传递O_CREAT.唯一的错误似乎就是这个错误.
Make sure that you are actually passing O_CREAT. Only that seems to be giving this error.
手册页显示ENOENT仅在两种情况下返回.对于shm_open,尽管只有第一个似乎有效.
Man page says ENOENT is returned only under two conditions. For shm_open only first one seems to be valid though.
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.
这篇关于shm_open()函数无此文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!