I have two processes (a producer and a consumer) communicating via a shared memory segment produced using the ‘old’ interface rather than mmap: The producer process could be restarted due to an error or configuration change. It creates a new region each time using the IPC_CREAT flag to shmget(). I have noticed that the consumer can continue to read from
Tag: shared-memory
Share Memory in Linux using C
Is it safe to use shm_unlink even there are other process currently open the shared memory? For exmaple: Process B shm_open and then Process A shm_unlink. Is it ok for Process B? Answer Yes, it is safe to call shm_unlink if another process has it opened. Per the man page for shm_unlink: The operation of shm_unlink() is analogous to unlink(2):
POSIX shared memory model
Is there a memory model specification for POSIX shared memory (across processes)? I’m hoping that there’s something to comparable to the C++ memory model, in order to answer questions like the following: Is there a definition of a data race? Are data races undefined behavior (as in C++)? Is there something to constrain memory visibility order across processes? I know
Segmentation fault error as the reader tries to read from the shared memory
I am trying to understand the System V shared memory APIs. I created a small program where one writes into the shared memory and another reads from the shared memory. But for some reason, I am getting an error : as I try to read from the shared memory. I could not find the reason for it. Here is what
how to use mmap and shm_open to shared memory among multiple independent processes
I want to share memory among processes, which run independently instead of fork. I’ve read the man page for mmap and shm_open, and still confused about the usage. shared memory, in my mind, should be the mechanism of mapping virtual memory space among different processes, but Why mmap has the fd argument? Does it mean the memory is actually shared
Storing and accessing an array of struct from shared memory
I am writing a program on a hotel reservation system and have declared a struct Room as follows: I use a variable read from an input file to create an array of n structs which is all the rooms in the hotel. I then create the shared memory space and attach it, but when I try to access it after,
Passing Variable Length C String Through Mmap-ed Shared Memory
Let’s say I have a process A and a process B, and process A would like to pass a C string to process B through a shm_open() + mmap() shared memory. What’s the most latency efficient way? The answer of this post suggested that after C++11, std::atomic is the right way to share data over shared memory. However, I fail
Segmentation fault appears when I use shared memory only from statically build program
When I built a program with –static option and it calls shm_open() function I get Segmentation fault. Without -static option all works like a charm. Does anybody know why? Below I have cited a debug info and a part of truncated source code from a big project. You can comment/uncomment string from Makefile to reproduce the bug. $ gdb –args
What type of memory objects does `shm_open` use?
Usually, shared memory is implemented using portions of On-Disk files mapped to processes address spaces. Whenever a memory access occurs on the shared region, the filesystem is involved to write changes on the disk which is a great overhead. Typically, a call to fopen() returns a file descriptor which is passed to mmap() to create the file’s memory map. shm_open,
shmat() Permission denied even i have read access
In my simple code: I already have read access, but I got “shmat: Permission denied”. Do I have permission to write? Answer From man shmat: If SHM_RDONLY is specified in shmflg, the segment is attached for reading and the process must have read permission for the segment. Otherwise the segment is attached for read and write and the process must