5

When I looked through the man pages of shmat. It is described as the primitive function of the API is to attach the memory segment associated wih shmid it to the calling process' address space .

The questions I have are the following.

  • The term attach looks generic to me. I find difficulties in understanding what is the underlying acivity that attach refers to.?
  • What it means by mapping a segment of memory?
4

2 回答 2

2

将其用作char *ptr=shmat(seg_id,NULL,0); 它通过函数将创建的段 id 附加到shmget()包含上述代码的进程中。

seg_id是新创建的段的段 id NULL意味着操作系统将代表用户处理段的起始地址 是两者的0标志read/write

每当一个进程附加到共享内存时,它必须被分离,以便另一个进程可以通过附加到该段来访问它(如果存在资源锁定机制。)

分离:shmdt(ptr);

于 2012-11-06T10:04:07.317 回答
1

这里有一个很好的解释:http: //www.makelinux.net/alp/035

“在 Linux 下,每个进程的虚拟内存都被分割成页。每个进程都维护着从其内存地址到这些虚拟内存页的映射,其中包含实际数据。即使每个进程都有自己的地址,但多个进程的映射可以指向同一页面,允许共享内存”

于 2012-11-06T10:02:22.983 回答