1. The traditional fork () function
Create a child process, child process and parent process share body segment, copy data segment, heap, stack to child process
As follows:
2.Linux fork () function-copy-on-write (Copy-on-write)
Create a child process, the kernel only creates virtual space for the child process, does not allocate physical memory, and the parent process shares the physical space,
The child process is allocated a physical space when the behavior of the corresponding segment is changed in the parent process.
As follows:
3.vfork () function
Create a child process that shares everything in the parent process.
As follows:
4. The difference between traditional fork and Copy-on-write
The traditional fork function simply replicates all the resources to a new process, which is inefficient.
When a copy is written, the data is copied, and no data is written, the cost of the fork () is actually simply copying the parent process's page table and creating a unique process descriptor for the child process. Before data is written, the data page to be changed is copied to the child process.
Linux write-time copy technology (Copy-on-write)