问题
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);
I've tried creating my own standalone app to run shm_open with the same name and options, and this is successful...
So checked that /dev/shm has drwxrwxrwt
permissions and that the process running the actual code has -rwxrwxrwx
permissions.
Also, mount | grep shm
returns:
tmpfs on /dev/shm type tmpfs (rw)
I'm out of ideas... any suggestions on what could be going wrong?
Thanks.
回答1:
Make sure that you are actually passing O_CREAT. Only that seems to be giving this error.
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.
来源:https://stackoverflow.com/questions/18985940/shm-open-function-no-such-file-or-directory