Suppose I have shared library with this function where "i" is some global variable.

```
int foo() {
return i++;
}

```

When I call this function from multiple processes the value of "i" in each process is independent on the other processes.

This behavior is quite expected.

I was just wondering how is usually this behavior implemented by the linker? From my understanding the code is shared between processes, so the variable has to have the same virtual address in all address spaces of every program that uses this library. That condition seems quite difficult to accomplish to me so I guess I am missing something here and it is done differently.

Can I get some more detailed info on this subject?