[clug-progsig] C Question about using fork() in Linux
irvins at alumni.uwaterloo.ca
Fri Sep 3 12:25:34 PDT 2004
The entire program is cloned when you call fork(). Each of the two running copies runs in its own process. One is called the parent process, and the other the child process. The way the code can test whether it's running in the parent or child process is by the return value of the fork() call. In the parent, the return value is the child process's process id (pid). In the child process, the return value is 0, which is not a valid pid.
If you are a beginning programmer just learning C (which your question strongly suggests) then I'd advise not messing with fork() until you are more advanced. A beginner would be way out of his depth here.
More information about the clug-progsig