Fork

From Hackepedia
Revision as of 10:41, 5 October 2005 by Pbug (talk | contribs)
Jump to navigationJump to search

A Unix process gets created by the fork system call. When fork is called inside a program it will create a child process that is similar to its parent(caller of fork). Similarities are: the executable image is copied including stack and heap as well as memory mappings(see copy-on-write), file descriptors and locks are copied, the process name is the same. After forking the exec system call is often called in order to make the intended program run. When the fork system call is called it will return 0 in the child and the pid of the child in the parent. If it fails it will return -1 and set errno.



Many clueful system administrators limit how many processes can be forked or else you have a run-away phenomenon called a fork-bomb which happens to creep up in Linux even today.