I quote \"when a process creates a new process using fork() call, Only the shared memory segments are shared between the parent process and the newly forked child process. C
You're probably running your program on an operating system with virtual memory. After the fork()
call, the parent and child have separate address spaces, so the address 0x1370010
is not pointing to the same place. If one process wrote to *x
, the other process would not see the change. (In fact those may be the same page of memory, or even the same block in a swap-file, until it's changed, but the OS makes sure that the page is copied as soon as either the parent or the child writes to it, so as far as the program can tell it's dealing with its own copy.)