I have two programs in C that need to communicate with each other. There is a single variable that I am storing in shared memory using shmget(key, 27, IPC_CREAT | 0666) in one program. I update this variable every 1 second. From the other program, I access it every 1 second using shmget(key, 27, 0666).
This works great, but after a while (usually a few hours), the program that retrieves the data crashes with a segfault. I used gdb to pinpoint the seg fault to the shmget(key, 27, 0666) line. The error code returned is:
ENOMEM Could not allocate memory for the descriptor or for the page tables.
When I check the shared memory segments from the command prompt using ipcs -m, I currently see this:
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status
0x00000000 65536 root 600 393216 2 dest
0x00000000 98305 root 600 393216 2 dest
0x00000000 131074 root 600 393216 2 dest
0x00000000 163843 root 600 393216 2 dest
0x00000000 196612 root 600 393216 2 dest
0x00000000 229381 root 600 393216 2 dest
0x00000000 262150 root 600 393216 2 dest
0x00000000 294919 root 600 393216 2 dest
0x00000000 327688 root 600 393216 2 dest
0x00000000 589833 root 600 393216 2 dest
0x00000000 655370 root 600 393216 2 dest
0x00000000 524299 root 600 393216 2 dest
0x00000000 688140 root 666 27 0
0x0008aa53 720909 root 666 27 31950
0x0006f855 753678 root 666 27 33564
It seems to me like there's an issue with the shared memory I'm using hitting some kind of maximum? But I'm not sure what to do about that, and I'm finding precious little info by google searching. Any thoughts? This program needs to run for ~24 hours at a time at least, if not longer.
Thank you in advance.