If I create shared memory variables in C, where are they placed (heap / stack / data section / ...)? I am using 64 bit Ubuntu with gcc-4.8 and the compilerflag -m32 for 32bit and this code:
segment_id = shmget (IPC_PRIVATE, shared_segment_size,
IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
shared_memory = (char*) shmat (segment_id, 0, 0);
printf ("shared memory attached at address |%10p\n", shared_memory);
I get the following output for this:
shared memory attached at address |0xf76de000
However, valgrind gives this:
shared memory attached at address | 0x4039000
Why? Do shared variables have anything to do with the extern keyword? If another process wants to use the data, can he choose where to attach the memory?