Fork (operating System) - Fork and Page Sharing

Fork and Page Sharing

When a fork system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by the OS for the child process. But this is not needed in certain cases. Consider the case when a child executes an "exec" system call (which is used to execute any executable file from within a C program) or exits very soon after the fork. When the child is needed just to execute a command for the parent process, there is no need for copying the parent process' pages, since exec replaces the address space of the process which invoked it with the command to be executed.

In such cases, a technique called copy-on-write (COW) is used. With this technique, when a fork occurs, the parent process's pages are not copied for the child process. Instead, the pages are shared between the child and the parent process. Whenever a process (parent or child) modifies a page, a separate copy of that particular page alone is made for that process (parent or child) which performed the modification. This process will then use the newly copied page rather than the shared one in all future references. The other process (the one which did not modify the shared page) continues to use the original copy of the page (which is now no longer shared). This technique is called copy-on-write since the page is copied when some process writes to it.

Read more about this topic:  Fork (operating System)

Famous quotes containing the words fork and, fork, page and/or sharing:

    Eye of newt and toe of frog,
    Wool of bat and tongue of dog,
    Adder’s fork and blind-worm’s sting,
    Lizard’s leg and owlet’s wing,
    For a charm of powerful trouble,
    Like a hell-broth boil and bubble.
    William Shakespeare (1564–1616)

    Eye of newt and toe of frog,
    Wool of bat and tongue of dog,
    Adder’s fork and blind-worm’s sting,
    Lizard’s leg and owlet’s wing,
    For a charm of powerful trouble,
    Like a hell-broth boil and bubble.
    William Shakespeare (1564–1616)

    Digressions, incontestably, are the sunshine;Mthey are the life, the soul of reading!—take them out of this book, for instance,—you might as well take the book along with them;Mone cold external winter would reign in every page of it; restore them to the writer;Mhe steps forth like a bridegroom,—bids All-hail; brings in variety, and forbids the appetite to fail.
    Laurence Sterne (1713–1768)

    If then there is any encouragement in Christ, any consolation from love, any sharing in the Spirit, any compassion and sympathy, make my joy complete: be of the same mind, having the same love, being in full accord and of one mind.
    Bible: New Testament, Philippians 2:1-2.