FACTOID # 41: On the probability of not reaching 40 graph, the top 34 countries are all African.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Fork (computing)
The title given to this article is incorrect due to technical limitations. The correct title is "fork".

A fork, when applied to computing is 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.


Under Unix and Unix-like operating systems, the parent and the child operations are selected by use of the return value of fork().


Example

Here 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 are executed simultaneously.

 int i, 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: %d n", 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: %d n", i); sleep(1); } } else { /* Error handling. */ fprintf(stderr, "couldn't fork"); 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


  Results from FactBites:
 
Fork (operating system) - Wikipedia, the free encyclopedia (566 words)
A fork, when applied to computing is 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.
Forking is an important part of Unix, critical to the support of its design philosophy, which encourages the development of filters.
Bin's On-Line Dictionary (421 words)
Fork beam (Shipbuilding), a half beam to support a deck, where hatchways occur.
The forks of a river or a road, the branches into which it divides, or which come together to form it; the place where separation or union takes place.
A fork followed by an exec can be used to start a different process but this can be inefficient and some later Unix variants provide vfork as an alternative mechanism for this.
  More results at FactBites »


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m