我正在尝试使用shm_open()创建一个新的共享内存文件,但我得到错误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)
我没有想法......关于可能出现什么问题的任何建议?
感谢。
答案 0 :(得分:0)
确保您实际上正在传递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.