I am new to fork (), I read everywhere that when fork () is called, an exact copy of the current (calling) process starts. Now, when I run the following code, there should be two different processes, with two different memory cells assigned to their vars and functions.
#include<stdio.h>
int i=10;
int pid;
int main(){
if((pid=fork())==0){
i++;
printf("parent address= %p\n",&i);
}else{
i++;
i++;
printf("child address= %p\n",&i);
}
wait(0);
return(0);
}
Why The output looks like ::
child address :: 804a01c
parent address :: 804a01c
Why are both addresses the same for parent and child?
source
share