Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Fork (system call)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Overview == In multitasking operating systems, processes (running programs) need a way to create new processes, e.g. to run other programs. Fork and its variants are typically the only way of doing so in Unix-like systems. For a process to start the execution of a different program, it first forks to create a copy of itself. Then, the copy, called the "[[child process]]", makes any environment changes the child will need and then calls the [[exec (system call)|exec]] system call to overlay itself with the new program: it ceases execution of its former program in favor of the new. (Or, in rarer cases, the child forgoes the [[exec (system call)|exec]] and continues executing, as a separate process, some other functionality of the original program.) The fork operation creates a separate [[address space]] for the child. The child process has an exact copy of all the memory segments of the parent process. In modern UNIX variants that follow the [[virtual memory]] model from [[SunOS]]-4.0, [[copy-on-write]] semantics are implemented and the physical memory need not be actually copied. Instead, [[virtual memory pages]] in both processes may refer to the same pages of [[physical memory]] until one of them writes to such a page: then it is copied. This optimization is important in the common case where fork is used in conjunction with exec to execute a new program: typically, the child process performs only a small set of actions before it ceases execution of its program in favour of the program to be started, and it requires very few, if any, of its parent's [[data structure]]s. When a process calls fork, it is deemed the [[parent process]] and the newly created process is its child. After the fork, both processes not only run the same program, but they resume execution as though both had called the system call. They can then inspect the call's [[return value]] to determine their status, child or parent, and act accordingly.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)