fork (system call)

It is usually implemented as a C standard library wrapper to the fork, clone, or other system calls of the kernel.

One of the earliest references to a fork concept appeared in A Multiprocessor System Design by Melvin Conway, published in 1962.

[1] Conway's paper motivated the implementation by L. Peter Deutsch of fork in the GENIE time-sharing system, where the concept was borrowed by Ken Thompson for its earliest appearance[2] in Research Unix.

Since there is absolutely no page copying involved (consuming additional memory), this technique is an optimization over plain fork in full-copy environments when used with exec.

In POSIX, using vfork for any purpose except as a prelude to an immediate call to a function from the exec family (and a select few other operations) gives rise to undefined behavior.

The difference between the System V approach and the BSD approach is philosophical: Should the kernel hide idiosyncrasies of its implementation from users, or should it allow sophisticated users the opportunity to take advantage of the implementation to do a logical function more efficiently?Similarly, the Linux man page for vfork strongly discourages its use:[7][failed verification][discuss] It is rather unfortunate that Linux revived this specter from the past.

Users should not depend on the memory sharing semantics of vfork() as it will, in that case, be made synonymous to fork(2).

"Other problems with vfork include deadlocks that might occur in multithreaded programs due to interactions with dynamic linking.

[12] As a replacement for the vfork interface, POSIX introduced the posix_spawn family of functions that combine the actions of fork and exec.

These functions may be implemented as library routines in terms of fork, as is done in Linux,[12] or in terms of vfork for better performance, as is done in Solaris,[12][13] but the POSIX specification notes that they were "designed as kernel operations", especially for operating systems running on constrained hardware and real-time systems.

[16] Both FreeBSD[17] and IRIX adopted the rfork system call from Plan 9, the latter renaming it "sproc".

clone is a system call in the Linux kernel that creates a child process that may share parts of its execution context with the parent.

The "separate stacks" feature from Plan 9 and IRIX has been omitted because (according to Linus Torvalds) it causes too much overhead.

The parent process passes this identifier to the waitpid system call to suspend execution until the child has exited.