fork() system call and memory space of the process

前端 未结 6 407
一个人的身影
一个人的身影 2020-12-24 08:54

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

6条回答
  •  情话喂你
    2020-12-24 09:32

    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.)

提交回复
热议问题