I was reading a textbook which talks about how fork()
work with virtual memory as:
When the fork function is called by the current process, the kernel creates various data structures for the new process and assigns it a unique PID. To create the virtual memory for the new process, it creates exact copies of the current process’s mm_struct, area structs, and page tables. It flags each page in both processes as read-only, and flags each area struct in both processes as private copy-on-write
I don't understand why it needs to flag each page in both processes as read-only.If each page in the parent process is read-only then the parent process will never be able to modify some uninitialised global variables(in .bss
section), then how is the program going to work?