Fork - same memory addresses?

前端 未结 5 799
青春惊慌失措
青春惊慌失措 2020-12-01 11:18

This is about C in Linux.

I have fork() in main() where I create 2 child processes. Then, in both child process a run the function ab

5条回答
  •  生来不讨喜
    2020-12-01 11:52

    since you are printing the address of stack variable(local variable). its address will be same(does't matter you update its value or not). since both the process share a common virtual stack.

    but if you are trying to print the address of a global variable inside common function(called from parent and child process) then its address will be same till the point you don't update it value. if a process update the value of global variable then that process will have unique copy of it(through copy on write mechanism).

提交回复
热议问题