Here\'s my setup...
/* Bounded Buffer item structure */
struct item {
int id; /* string index value */
char str[80]; /* string value */
};
/* Str
when a process calls shmat(), it will return the virtual address of the shared memory. virtual address is the memory location as seen by the current process. different process can map the shared memory to different virtual address in the process address space and hence different return values of shmat() call for different processes.
a nice pictorial description of what I just said above. http://poshmodule.sourceforge.net/posh/html/node3.html
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.
It's perfectly legal for the same shared memory segment to be mapped at different virtual addresses in different processes.