int shmid;
int* locat;
//create shared memory segment
shmid = shmget(6666, size, 0666);
if (shmid < 0) {
perror("shmget");
exit(1);
}
locat = (int *) shmat(shmid, NULL, 0);
if (locat == (int *) -1) {
perror("shmat");
exit(1);
}
我设立共享内存作为这样的,但我不断收到此错误:shmget: No such file or directory
共享内存在C:shmget的问题
此代码工作正常,不知道为什么现在这个发生。
您的共享内存创建失败,'shmget'返回'-1'。看看http://stackoverflow.com/questions/7495326/understanding-shared-memory-using-c – MrKiwi