shm_overview(7)
๐ shm_overview(7) ๐
okay bestie, sit down, hydrate, because today we're talking about shm_overview โ the whole vibe tour of POSIX shared memory. this is section 7, misc info manual energy, and yes it's gonna be cute AND correct. ๐ซถ
โจ NAME โจ
shm_overview โ the big-picture overview of POSIX shared memory. like, the concept, the lore, the whole thing. ๐
๐ธ DESCRIPTION ๐ธ
so here's the tea: the POSIX shared memory API lets processes talk to each other by literally sharing a chunk of memory. same bytes, multiple processes, no cap. ๐ง โจ
the interfaces that make up this API are:
shm_open(3)โ makes a brand new object or opens one that already exists. it's givingopen(2)energy, fr. it hands you back a file descriptor that all the other calls below use. ๐ftruncate(2)โ sets the size of the shared memory object. and heads up: a freshly created shared memory object starts out with a length of zero, so yeah, you gotta set this. ๐mmap(2)โ maps that shared memory object right into the virtual address space of the process that's calling it. main character move. ๐munmap(2)โ unmaps it back out of the calling process's virtual address space. bye bestie ๐shm_unlink(3)โ removes a shared memory object's name. ๐ (not the object itself necessarily โ the name, iykyk)close(2)โ closes the file descriptor thatshm_open(3)gave you, for when you're done with it and don't need it anymore.fstat(2)โ grabs astatstructure describing the shared memory object. among the stuff it hands back: the object's size (st_size), permissions (st_mode), owner (st_uid), and group (st_gid). receipts! ๐fchown(2)โ for changing the ownership of a shared memory object.fchmod(2)โ for changing the permissions of a shared memory object.
๐ฆ Versions
POSIX shared memory has been around since Linux 2.4 and glibc 2.2. vintage but thriving, honestly. โญ
๐ Persistence
POSIX shared memory objects have kernel persistence, which basically means they hang around. a shared memory object will keep existing until:
- the system gets shut down, or
- all processes have unmapped the object and it's been deleted with
shm_unlink(3)
so yeah, it does NOT just vanish when your program exits. it's committed. ๐ค
๐ฅ Linking
if your program uses the POSIX shared memory API, you must compile it with:
cc -lrt
because you need to link against the real-time library, librt. don't skip this step, it WILL be a whole thing. ๐
๐ Accessing shared memory objects via the filesystem
on Linux, shared memory objects live inside a tmpfs(5) virtual filesystem, normally mounted under /dev/shm. and since Linux 2.6.19, Linux supports using access control lists (ACLs) to control permissions of objects in that virtual filesystem. fancy. ๐
๐ NOTES ๐
- typically, processes have to synchronize their access to a shared memory object โ using, for example, POSIX semaphores. no just winging it, bestie, that's how you get chaos. ๐ญ
- System V shared memory (
shmget(2),shmop(2), etc.) is the older shared memory API. POSIX shared memory gives you a simpler, better designed interface โ but on the flip side, POSIX shared memory is somewhat less widely available (especially on older systems) than System V shared memory. so like, tradeoffs. โ๏ธ
๐ SEE ALSO ๐
fchmod(2), fchown(2), fstat(2), ftruncate(2), memfd_create(2), mmap(2), mprotect(2), munmap(2), shmget(2), shmop(2), shm_open(3), shm_unlink(3), sem_overview(7)
and that's the whole page, periodt. ๐ this lil tour came from Linux man-pages 6.20, dated 2025-05-17 โ so if you're quoting it, that's the source and the date, bestie. go forth and share that memory responsibly ๐๐ฆโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms