Skip to content

dlee-libo/cs-style-shared-memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Shared Memory via memfd_create and Unix Domain Sockets

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.

How It Works

  1. 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.
  2. Server side

    • Receive the FD over the socket.
    • Perform its own mmap to map the shared memory region into its address space.
    • Both processes can now access the same shared memory.

Benefits

  • 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.

TODO / Next Steps

  • 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 futex for lightweight locking.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages