|
A fork, when applied to computing occurs when a process creates a copy of itself, which then acts as a "child" of the original process, now called the "parent". More generally, a fork in a multithreading environment means that a thread of execution is duplicated. Image File history File links Mergefrom. ...
It has been suggested that this article or section be merged into Fork (operating system). ...
RAM (Random Access Memory) Look up computing in Wiktionary, the free dictionary. ...
In computing, a process is, roughly speaking, a task being run by a computer, often simultaneously with many other tasks. ...
A child process is a computer process created by another process (the parent process). ...
A parent process is a computer process that has created one or more child processes. ...
Many programming languages, operating systems, and other software development environments support what are called threads of execution. ...
Many programming languages, operating systems, and other software development environments support what are called threads of execution. ...
Under Unix and Unix-like operating systems, the parent and the child operations are selected by examining the return value of the fork() system call. In the child process, the return value of fork() is 0, whereas the return value in the parent process is the PID of the newly-created child process. Filiation of Unix and Unix-like systems Unix (officially trademarked as UNIX®) is a computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. ...
Diagram of the relationships between several Unix-like systems A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification. ...
In computing, an operating system (OS) is the system software responsible for the direct control and management of hardware and basic system operations. ...
In computing, a system call is the mechanism used by an application program to request service from the operating system. ...
In computing, the process identifier (normally referred to as the process ID or just PID) is a number used by some operating system kernels (such as that of UNIX or Windows NT) to uniquely identify a process. ...
As soon as fork is called, there will be a separate address space created for the child. The child process will have an exact copy of all the segments of the parent process, though if copy-on-write semantics are implemented actual physical memory may not be assigned. Both the parent and child processes may execute independently of each other. Copy-on-write (sometimes referred to as COW) is an optimization strategy used in computer programming. ...
Importance of Fork In Unix Forking is an important part of Unix, critical to the support of its design philosophy, which encourages the development of filters. In Unix, a filter is a small program that reads its input from stdin, and writes its output to stdout. A pipeline of these commands can be strung together by a shell to create new commands. For example, one can string together the output of the find(1) command and the input of the wc(1) command to create a new command that will print a count of files ending in ".cpp" found in the current directory, as follows: In UNIX and UNIX-like operating systems, a filter is program that gets most of its data from standard input and writes its main results to standard output. ...
Screenshot of a sample Bash session, taken on Gentoo Linux. ...
$ find . -name "*.cpp" -print | wc -l In order to accomplish this, the shell forks itself, and uses pipes, a form of interprocess communication, to tie the output of the find command to the input of the wc command. Two child processes are created, one for each command (find and wc). These child processes are overlaid with the code associated with the programs they are intended to execute, using the exec(3) family of system calls (in the above example, find will overlay the first child process, and wc will overlay the second child process, and the shell will use pipes to tie the output of find with the input of wc). A pipeline of three programs run on a text terminal In Unix-like computer operating systems, a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process (stdout) feeds directly as input (stdin) of the next one. ...
Inter-process communication (IPC) is the exchange of data between one process and another, either within the same computer or over a network. ...
In operating systems, an overlay is when a process replaces itself with the code of another program. ...
More generally, forking is also performed by the shell each time a user issues a command. A child process is created by forking the shell, and the child process is overlaid, once again by exec, with the code associated with the program to be executed.
Example Below is some sample C programming language code to illustrate the idea of forking. The code that is in the "Child process" and "Parent process" sections is executed simultaneously in two different processes. C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. ...
pid_t pid; pid = fork(); if (pid == 0) { /* Child process: * When fork() returns 0, we are in * the child process. * Here we count up to ten, one each second. */ int j; for (j = 0; j < 10; j++) { printf("child: %dn", j); sleep(1); } _exit(0); /* Note that we do not use exit() */ } else if (pid > 0) { /* Parent process: * Otherwise, we are in the parent process. * Again we count up to ten. */ int i; for (i = 0; i < 10; i++) { printf("parent: %dn", i); sleep(1); } } else { /* Error handling. */ fprintf(stderr, "can't fork, error %dn", errno); exit(1); } This code will print out the following: parent: 0 child: 0 child: 1 parent: 1 parent: 2 child: 2 child: 3 parent: 3 parent: 4 child: 4 child: 5 parent: 5 parent: 6 child: 6 child: 7 parent: 7 parent: 8 child: 8 child: 9 parent: 9 The order of each output is determined by the kernel.
See also A child process is a computer process created by another process (the parent process). ...
A parent process is a computer process that has created one or more child processes. ...
This article does not cite any references or sources. ...
Fork-exec is a commonly used technique in Unix whereby an executing process spawns a new program. ...
The exec functions of the Unix and POSIX operating systems load and execute a new child process by placing it in memory previously occupied by the parent process. ...
An exit, when applied to computing, is when a process terminates execution. ...
In modern computer operating systems, a process (or task) may wait on another process to complete its execution. ...
External links |