shmat() is returning a different “shmaddr” for same “shmkey”

后端 未结 3 737
-上瘾入骨i
-上瘾入骨i 2020-12-21 07:41

Here\'s my setup...

/* Bounded Buffer item structure */
struct item {
    int  id;  /* string index value */
    char str[80];  /* string value */
};

/* Str         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-21 08:01

    There are two sets of addresses involved. The "Chip RAM addresses," aka hardware, physical, real, or supervisor addresses, start at your first RAM chip at 0 and move upwards. However, on all "true multi-tasking" operating systems, each process gets its own "virtual memory." The CPU and OS collaborate to give each process the "illusion" that it is alone on its own machine, with its own address space, with a table (in the kernel and CPU, depending on architecture) mapping from the "virtual" (per-process) addresses to the "real/hardware/supervisor" addresses.

    Shared memory is a special case, where the same "real memory" is addressed from more than one process. The virtual addresses that "shmat" returns are local to each caller.

    Likewise, when you load a shared object (.so) library, it may be mapped into a different address space in each process.

提交回复
热议问题