Difference between revisions of "Fork"

From Hackepedia
Jump to navigationJump to search
 
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
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 exactly the same as its parent(caller of fork).  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]].
+
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]] [[syscall]] 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]].
  
  

Latest revision as of 13:58, 26 October 2005

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 syscall 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.