/* configure the size of the shared memory segment */ ftruncate(shm_fd,SIZE);
/* now map the shared memory segment in the address space of the process */ ptr = mmap(0,SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); if (ptr == MAP_FAILED) { printf("Map failed\n"); return-1; }
/** * Now write to the shared memory region. * * Note we must increment the value of ptr after each write. */ char *str = (char *)ptr; sprintf(str,"%s",message0); str += strlen(message0); sprintf(str,"%s",message1); str += strlen(message1); sprintf(str,"%s",message2); str += strlen(message2); display("prod", ptr, 64);