The heap segment is used for dynamic memory allocation during the program's execution. This segment also uses the copy-on-write mechanism which is implemented as:
The kernel initially maps the child's heap segment to the same physical pages as the parent's heap segment.
The pages are marked as read-only, and any attempt to modify these pages results in a page fault.
Upon a page fault, the kernel copies the affected page and updates the page table entry for the process that caused the fault.