Shared Memory Segments and Message Queues

Mar 24, 2019 11:34 · 119 words · 1 minute read

In project 3, I learned a couple different IPC (interprocess communication) methods in addition to socket based communication. In particular, I learned how to send messages over POSIX message queues; similarly, I learned how to use shared memory segments to avoid the performance overhead of the kernel copying data to user space.

Before two processes can use the shared memory segment, they both need to open it up using the same name. After they both open up the shared memory segment, they each need to call mmap, which returns a pointer to the memory segment. Once that’s done, the two processes can write/read to/from the shared memory, synchornizing their accesses using either mutexes — or my preferred method: semaphores.