In addition to the copy-on-write bit, the page table also has a link counter. Therefore, when the children are forks, all non-personal pages in the parent are marked as COW, and the link count is incremented.
Then, while the child process is running, and the parent writes the page, it will receive a page error, and the page will be copied as you would expect, and the number of links will decrease. When a child leaves, he reduces all links to pages with one, and pages with a zero link number are thrown away.
Now, when the parent writes the page with the COW bit set and the link count to one, the COW bit is simply ignored.
source
share