00001 00007 #include "h1.h" 00008 00015 int GetSharedMem(char* token) 00016 { 00017 key_t key; /*it's a long int */ 00018 int shm_id; 00019 00020 /* generate a random key based on a file name and char */ 00021 key = ftok(token, 'X'); 00022 if(key == -1) {perror("ftok"); return -1;} 00023 00024 /* now connect to (or possibly create) the shared memory segment with permission 644 */ 00025 shm_id = shmget(key, SHM_SIZE, 0644 | IPC_CREAT); 00026 if(shm_id == -1){perror("shmget"); return -1;} 00027 00028 return shm_id; 00029 }