When a process is forked, the child process is created which shares the virtual address space, but when either of the process tries to modify a shared page, a copy of that page is made, ensuring changes are private to each process. The steps of copy-on-write mechanism are:-
After fork, both process share the same memory pages and page table entries are marked as read-only.
When a process tries to write to a shared page, a page fault occurs because the page is marked read-only.
The kernel handles the page fault by copying the original page to a new location and the process that attempted the write now has a writable copy of the page.
The page table entries are updated to reflect the new page locations and permissions.