Specifically, how does fork() handle dynamically allocated memory from malloc() in Linux?

后端 未结 4 740
故里飘歌
故里飘歌 2020-12-05 06:39

I have a program with a parent and a child process. Before the fork(), the parent process called malloc() and filled in an array with some data. After the fork(), the chil

4条回答
  •  广开言路
    2020-12-05 07:28

    After a fork the child is completely independent from the parent, but may inherit certain things that are copies of the parent. In the case of the heap, the child will conceptually have a copy of the parents heap at the time of the fork. However, modifications to the head in the child's address space will only modify the child's copy (e.g. through copy-on-write).

    As for the documentation: I've noticed that documentation will usually state that everything is copied, except for blah, blah blah.

提交回复
热议问题