Cygwin/Cygserver 共享内存

标签 c cygwin shared-memory

我试图将一些共享内存代码从 CENTOS(3.5) 迁移到 CYGWIN(2.8.1, win10)。 共享内存通常是这样工作的:

  1. 通过 shmget 在进程中生成共享内存。

  2. 通过shmat映射该进程上的共享内存并记录位置,然后将一些信息填充到内存中。

  3. 通过“shmat”将共享内存映射到另一个进程,传递最后记录的进程的位置,因为我们期望两个进程将共享内存映射到相同的地址。

下面是一些代码来解释:

// one process
size_t size = 1024 * 1024;//1M
int id = shmget(IPC_PRIVATE, size, 0660);
char *madr = 0;
char *location = shmat(id, madr, 0);

// another process
char *location1 = shmat(id, location , 0);
// !!!we hope location1 and location should be the same!!!

在 Centos 上它运行良好。

在 Cygwin 上,一个进程将共享内存映射到 0xffd90000,另一个进程与之不同,但映射到 oxffdb0000。我们检查内存 0xffd90000 在该进程上是否可用。

最佳答案

对 Linux 的期望也是错误的,请参阅
https://linux.die.net/man/2/shmat

Be aware that the shared memory segment attached in this way may be attached at different addresses in different processes. Therefore, any pointers maintained within the shared memory must be made relative (typically to the starting address of the segment), rather than absolute.

关于Cygwin/Cygserver 共享内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45788744/

相关文章:

c++ - C 或 C++ 中的 Csing for

c - malloc 产生 SIGTRAP 错误

c - 从 C 中的字符串填充二维整数数组

c++ - 无法在 Windows 上安装最新的 GCC

c - 从子进程中的共享内存读取指向共享内存的指针时出现段错误

c++ - 共享内存空间是否可以将数据(非 POD)发送到另一个共享内存?

c - 删除 HTTP header 信息

shell - 从 Cygwin 打开文件

java - "cygwin"终端下未处理的转义序列

python - 有效地将函数并行应用于分组的 pandas DataFrame