I am confused by this. I read that when a child is created by the parent process, child gets a copy of the parent address space. What does that mean, copy? If I use the code below, then it prints the same addresses of the variable 'a', which is on the heap in all cases. that is, in the case of the child and the parent. So what's going on here?
int main () {pid_t pid; int * a = (int *) malloc (4); printf ("heap pointer% p \ n", a); pid = fork (); if (pid <0) {fprintf (stderr, "Fork Failed"); Output (-1); } else if (pid == 0) {printf ("Child \ n"); printf ("in the child heap pointer% p \ n", a); } else {
wait (NULL); printf ("Child Complete\n"); printf ("in parent heap pointer %p\n", a); exit(0); }}
source share