考虑以下 C 程序:
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/types.h>
#include <string.h>
int main() {
const char* name = "/memmap_ipc_shm";
int shmFd = shm_open(name, O_RDWR | O_CREAT, 0777);
if (shmFd < 0) {
fprintf(stderr,"bad shmfd opening %s: %s\n", name, strerror(errno));
return -1;
}
return 0;
}
当我在我的 GNU/Linux 系统(Devuan Beowulf,Linux 5.10.0-9,amd64 CPU)上运行它时,我得到:
bad shmfd opening /memmap_ipc_shm: Permission denied
为什么我被拒绝许可?我很确定我遵循了man shm_open
页面中的所有指南,我请求的权限似乎没问题 - 那么有什么问题?