I have a somewhat strange problem that I seek help to solve.
My system is Debian Jessie 8.0 32bit
I have two processes (created in c++ by me) started as systemd services.
These two processes communicate with a memory mapped file created this way:
Code: Select all
MyShm * TaskImpl::getSharedMem()
{
MyShm* shm;
int fd = shm_open("/my_shared_mem", O_RDWR | O_CREAT, 0660);
if(fd == -1) {
//error logging removed
return NULL;
}
ftruncate(fd, sizeof(MyShm));
shm = (MyShm *)mmap(NULL, sizeof(MyShm),
PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
close(fd);
if(shm == MAP_FAILED) {
//error logging removed
return NULL;
}
return shm;
}
I see the mmap files created in /dev/shm.
If one of the processes is restarted it regains access to the mmap file and communication continues.
Now comes the strange part.
As soon as I log out of the system (I'm logged in as the same user as systemd is set to start the procceses under), the mmap files seems to be somehow deleted.
Communication between the processes continues withput problem. But, if one of the processes is restarted it tries to regain access to the mmap file which is no longer there. It thus creates a new file which does not correspond to the mmap through which the other process communicates. The outcome, the processes no longer talk to each other.
Why is the mmap files deleted when the user logs out?
What is the solution? Should I change something in my code, or change something on the system to prevent the files from being deleted.
Regards
//Klaus