How fork() work by copying parent process area str

2019-08-25 03:51发布

问题:

I'm a beginner in Linux and Virtual Memory, still struggling to understand how fork() works:

My textbook says that when the fork function is called by the current process, the kernel creates exact copies of the current process’s mm_struct, area structs, and page tables for the child process. I have questions about the page tables that being copied from parent process to child prcess.

1.If there is only one-level of page table used by parent process, my understanding is, when fork() is called, a new page table is created for the child process, the content of new child page tables is the same as old parent page table, but the child page table physical base address is different in RAM, that's how Linux can do context switch between processes by coping page table address into the dedicated register, is my understanding correct?

  1. If the system(Intel Core i7) uses multi-level page (four levels), we know that L1 page table entry stored the physical base address of L2 page table... etc. So when fork() is called, how Kernel copy the parent's four page tables to child process? since the lower level page table entry store the physical base address of next level page table, if it does an exact copy, the child process will share the L4 page table of its parent, which shouldn't be happening, should it?