This project demonstrates creating shared memory in a server/client process setup. Unlike the traditional parent/child process relationship, this approach allows an arbitrary client process to share memory with a server process.
-
Client side
- Create a file descriptor (FD) using
memfd_create. - Map that FD into the client’s memory space using
mmap. - Send the FD to the server process over a Unix domain socket.
- Create a file descriptor (FD) using
-
Server side
- Receive the FD over the socket.
- Perform its own
mmapto map the shared memory region into its address space. - Both processes can now access the same shared memory.
- Works across unrelated processes (not limited to forked parent/child).
- Uses Linux-native primitives (
memfd_create,mmap, Unix domain sockets). - Enables flexible IPC for high-performance applications.
- Define a protocol: prevent arbitrary or unauthorized clients from connecting.
- Synchronization: when multiple processes read/write to shared memory, proper synchronization is required. A common approach is using
futexfor lightweight locking.