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