我得到了以下成功执行的 C 代码:
...
fd = shm_open(memory_package_name, O_CREAT | O_RDWR | O_EXCL , S_IRUSR | S_IWUSR);
if (fd == -1) { //will fail if file already exists because of flag O_EXCL
printf("\n shm_open() failed with error [%s]\n",strerror(errno));
exit(EXIT_FAILURE);
} else {
printf("shm_open success\n");
}
...
使用ls -l /dev/shm
我看到name memory_package_name
正确创建的文件,但是当我使用ipcs
它时不显示任何共享内存段:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
------ Semaphore Arrays --------
key semid owner perms nsems
------ Message Queues --------
key msqid owner perms used-bytes messages
为什么?