Importance of Forking 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 (usually 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 and any subdirectories, as follows:
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. First, a pipe is created at two fresh file descriptors, and then two child processes are created, one for each command (find and wc). Each child process first dup2(2)s the appropriate pipe file descriptor to either its standard input or output. Then these child processes overlay themselves with the code associated with the programs they are intended to execute, using the exec(3) family of system calls.
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.
Read more about this topic: Fork (operating System)
Famous quotes containing the words importance of and/or importance:
“We have been told over and over about the importance of bonding to our children. Rarely do we hear about the skill of letting go, or, as one parent said, that we raise our children to leave us. Early childhood, as our kids gain skills and eagerly want some distance from us, is a time to build a kind of adult-child balance which permits both of us room.”
—Joan Sheingold Ditzion (20th century)
“For even satire is a form of sympathy. It is the way our sympathy flows and recoils that really determines our lives. And here lies the vast importance of the novel, properly handled. It can inform and lead into new places our sympathy away in recoil from things gone dead. Therefore the novel, properly handled, can reveal the most secret places of life: for it is the passional secret places of life, above all, that the tide of sensitive awareness needs to ebb and flow, cleansing and freshening.”
—D.H. (David Herbert)