I am trying to learn operating systems. At present i am in virtual addressing. What book says that if we have one static variable
and one local variable
and we update them and sleep for some time and try to print their addresses then across multiple such processes running one will get same memory address.
This is because each process feel like it has whole memory and has no control of physical memory so address will remain same among various process running at the same time. I understand this but when i run my program i am getting same address across static variables but different across local variables. With my little operating systems knowledge i am not able to understand why this is happening. This is my code
int staticvar = 0;
int main(int argc, char const *argv[])
{
int localvar = 0;
staticvar += 1;
localvar += 1;
sleep(10);
printf("static address: %x, value: %d\n", &staticvar, staticvar );
printf("static address: %x, value: %d\n", &localvar, localvar );
return 0;
}
This is my output when i run three different processes simultaneously.
./a.out
static address: 60104c, value: 1
static address: 67c6128c, value: 1
./a.out
static address: 60104c, value: 1
static address: 89e2c11c, value: 1
./a.out
static address: 60104c, value: 1
static address: 226e03dc, value: 1