0

Hello C experts,

main() {


int i=0;
int x;
fork();
fork();
fork();
i++;
x=&i;
printf("%d %x\n",i,x);
}

Each child process gets its own copy of i , but why does x not print different address ?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Conqueror07
1

Because with virtual memory every user process gets the same address range but different physical memory links...so every process appears to have the same memory but in reality it has its own copy of things like data...Note: most programs will shared some blocks of code i.e. Dlls and the text section of code can be shared..

As an experiment try changing the child processes x value and then display it....add x to the pid and then display it

Votes + Comments
Thanks.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.