Possible Duplicate:
After forking, are global variables shared?
In my C program, I keep a struct linked list as a global variable.
Then later I fork a child process. Now in the child process if I free a node of the linked list, and then end the child process. Will the node be gone in the parent process as well?
When I was trying this, it seems the node was still there in the parent process…
Is this right? Why?
No, it won’t be gone in the parent process. The correct mental model is that the child is getting an independent copy of the parent’s memory. The two processes are not sharing the memory (not unless you explicitly set up a shared memory segment and place your data there).
The situation is radically different if you use threads instead of processes. Threads running within the same process do share the address space.