// bugsbunny.c // by Michael Collins // #include #include #include #include int main() { key_t shkey = ftok("/dev/null",'A'); //Make a key identifier so daffy can find the shared memory int shared_id = shmget(shkey, 8192, IPC_CREAT); //Create a new shared memory segment char* sharedmem = shmat(shared_id, 0, 0); //Map it onto our virtual address space sprintf(sharedmem,"Duck Season"); //Lets make it Duck season. printf("I, Bugs, think it should be %s\n", sharedmem); while( strcmp(sharedmem,"Duck Season")==0 ); sprintf(sharedmem,"Duck Season"); //Daffy changed it to Rabbit season, better change it back! printf("Well, I, Bugs, say its %s\n", sharedmem); shmctl(shared_id,IPC_RMID,NULL); //Make sure it gets destroyed when everyone detaches from it shmdt(sharedmem); //Unmap the segment from our virtual space }