Я пытаюсь установить межпроцессное взаимодействие с использованием общей памяти.Вот определение структуры.
#define SHM_SIZE (519430400)
test_ht *CommandLine_Buffer;
typedef struct
{
int a;
int testnum;
st_cl cli[3];
}test_ht;
typedef struct
{
tHT CliInfo;
} st_cl;
typedef struct
{
int x;
} tHT;
Shared memory is created as below
int fd;
int ret_v;
void* addr;
int i;
fd = shm_open("SharedBuf.shm", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
ret_v = ftruncate(fd, SHM_SIZE);
SharedBuffer = mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, SEEK_SET);
I access the structure members as below
CommandLine_Buffer->cli[i].CliInfo.x
Здесь я могу читать и писать a
и testnum
по всей процедуре.Общая память создана успешно.В то же время я могу получить доступ к
CommandLine_Buffer->cli[0].CliInfo.x and CommandLine_Buffer->cli[1].CliInfo.x
Невозможно получить CommandLine_Buffer->cli[2].CliInfo.x
.
Любые советы по отладке этого или любую идею, почему я не могу прочитать последнее местоположение.