/* * Get a string from a shared memory segment of 512 bytes * New File Mar 22,1989 * Author Jerry LeVan * */ #include #include #include #include #define SIZE 512 /* shared memory buffer size */ #define KEY 'JHL ' /* our key */ main() { int memoryid; char * location; /* shmget will fail if not already created */ memoryid = shmget(KEY,SIZE,0); printf("status of key retreival = %d\n",memoryid); if(memoryid == -1) {perror("Bad Key"); exit();} /* we got the key now attach to the segment */ location = (char *)shmat(memoryid,0,0); /* we want read write access */ printf("status of attach = %d\n",location); if (location == (char*)-1) {perror("Bad Attach");exit();} /* now read string from the location */ printf("%s\n",location); }