#include #include #include #include #include #include #include #include #include int main() { //Size in bytes of the shared memory structure const int SIZE = 4096; //Name of the shared memory struct const char * name = "SHMEM"; //Messages to write to shared memory const char * message_1 = "Hello"; const char * message_2 = "There"; //File descriptor for shared memory file int fd_shm; //Void pointer that points to the shared memory struct void * shm_ptr; //Create shmem object using the shm_open function fd_shm = shm_open(name, O_CREAT | O_RDWR, 0666); //Set the size of the shared memory object ftruncate(fd_shm, SIZE); //Memory map the shared struct. shm_ptr = mmap(0, SIZE, PROT_WRITE, MAP_SHARED, fd_shm, 0); //Write to the shared memory struct. sprintf(shm_ptr, "%s", message_1); shm_ptr = shm_ptr + strlen(message_1); sprintf(shm_ptr, "%s", message_2); shm_ptr = shm_ptr + strlen(message_2); return 0; }