The traditional Unix system call to duplicate a process is fork. However, it is not the only call implemented by Linux for this purpose — in fact, there are three:
7Kernel versions before 2.6.21 had three helper functions: younger_sibling, older_sibling, and eldest_child, which gave some aid in accessing the described lists and their elements. They were used to produce debugging output, which had, however, not proved very useful, so it was removed. Patch author Ingo Molnar noticed that the corresponding code was among the oldest elements of the kernel and noted this accordingly. This led another well-known developer to sign off the patch as Linus 'snif' Torvalds ...
1. fork is the heavy-weight call because it creates a full copy of the parent process that then executes as a child process. To reduce the effort associated with this call, Linux uses the copy-on-write technique, discussed below.
2. vfork is similar to fork but does not create a copy of the data of the parent process. Instead, it shares the data between the parent and child process. This saves a great deal of CPU time (and if one of the processes were to manipulate the shared data, the other would notice automatically).
vfork is designed for the situation in which a child process just generated immediately executes an execve system call to load a new program. The kernel also guarantees that the parent process is blocked until the child process exits or starts a new program.
Quoting the manual page vfork(2), it is ''rather unfortunate that Linux revived this specter from the past.'' Since fork uses copy-on-write, the speed argument for vfork does not really count anymore, and its use should therefore be avoided.
3. clone generates threads and enables a decision to be made as to exactly which elements are to be shared between the parent and the child process and which are to be copied.
Continue reading here: Copy on Write
Was this article helpful?