1

shmat returns segmentation falut with errno=13(EACCES)

view story
linux-howto

http://stackoverflow.com – I just want test shmget() and shmat() , but something seems wrong. :( shmget() works well but shmat() causes segmentation fault. this is the code: #include <stdlib.h> #include <sys/ipc.h> #include <sys/shm.h> #include <stdio.h> #include <errno.h> int main(void) { key_t key=98;/* yes, just 98 for test */ int shid; char *str=NULL; shid = shmget(key, 4096, IPC_CREAT); printf("shid:%d\n",shid); str=(char*)shmat(shid,NULL,0); printf("str:%d\n",(int)str); printf("errno:%d\n", errno); str[0] = 'h'; str[1] = '\0'; return 0 (HowTos)