c - 通过共享内存进行进程间通信
问题描述
我正在尝试使用共享内存进行进程间通信。这是结构定义。
#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
。
调试此的任何提示或任何想法为什么无法读取最后一个位置。
解决方案
推荐阅读
- php - 收到通知的模板上的下一页/上一页链接
- apollo - 任何地方都有人类可读的堆栈跟踪吗?
- angular - 以角度处理表格中的单击事件
- encryption - rijndael 加密支持 java
- python - 如何修复 django 模板中的 html 代码
- java - 在 RingOut API 之后在 RingCentral 中记录调用
- unity3d - Unity AR Foundation(iOS):如何在前置摄像头中使用身体追踪
- c++ - 使用对象指针时如何访问成员函数
- bootstrap-4 - Jqgrid `columnChooser` bootstrap4 支持 css
- python-3.x - “from keras.models import Sequential”和“from tensorflow.python.keras.models import Sequential”有什么区别?