Question: In many programs and man pages of Linux, I have seen code using `fork()`. Why do we need to use `fork()` and what is its purpose?

Answer: 
`fork()` is how you create new processes in Unix. When you call `fork`, you're creating a copy of your own process that has its own [address space](http://en.wikipedia.org/wiki/Address_space). This allows multiple tasks to run independently of one another as though they each had the full memory of the machine to themselves.

Here are some example usages of `fork`:

1. Your [shell](http://en.wikipedia.org/wiki/Shell_(computing)) uses `fork` to run the programs you invoke from the command line.
2. Web servers like [apache](http://www.apache.org/) use `fork` to create multiple server processes, each of which handles requests in its own address space. If one dies or leaks memory, others are unaffected, so it functions as a mechanism for fault tolerance.
3. [Google Chrome](http://www.google.com/chrome) uses `fork` to handle each page within a separate process. This will prevent client-side code on one page from bringing your whole browser down.
4. `fork` is used to spawn processes in some parallel programs (like those written using [MPI](http://www.mcs.anl.gov/research/projects/mpi/)). Note this is different from using [threads](http://en.wikipedia.org/wiki/Thread_(computer_science)), which don't have their own address space and exist *within* a process.
5. Scripting languages use `fork` indirectly to start child processes. For example, every time you use a command like [`subprocess.Popen`](http://docs.python.org/library/subprocess.html#module-subprocess) in Python, you `fork` a child process and read its output. This enables programs to work together.

Typical usage of `fork` in a shell might look something like this:

```
int child_process_id = fork();
if (child_process_id) {
    // Fork returns a valid pid in the parent process.  Parent executes this.

    // wait for the child process to complete
    waitpid(child_process_id, ...);  // omitted extra args for brevity

    // child process finished!
} else {
    // Fork returns 0 in the child process.  Child executes this.

    // new argv array for the child process
    const char *argv[] = {"arg1", "arg2", "arg3", NULL};

    // now start executing some other program
    exec("/path/to/a/program", argv);
}

```

The shell spawns a child process using `exec` and waits for it to complete, then continues with its own execution. Note that you don't have to use fork this way. You can always spawn off lots of child processes, as a parallel program might do, and each might run a program concurrently. Basically, any time you're creating new processes in a Unix system, you're using `fork()`. For the Windows equivalent, take a look at [`CreateProcess`](http://msdn.microsoft.com/en-us/library/ms682425.aspx).

If you want more examples and a longer explanation, [Wikipedia](http://en.wikipedia.org/wiki/Fork_(operating_system)) has a decent summary. And [here are some slides](http://courses.cs.vt.edu/~cs3204/spring2009/butta/local/lectures/lecture-07.pdf) here on how processes, threads, and concurrency work in modern operating systems.
The rationale behind fork() versus just having an exec() function to initiate a new process is explained in [an answer to a similar question on the unix stack exchange](https://unix.stackexchange.com/questions/31118/why-is-the-default-process-creation-mechanism-fork).

Essentially, since fork copies the current process, all of the various possible options for a process are established by default, so the programmer does not have supply them.

In the Windows operating system, by contrast, programmers have to use the CreateProcess function which is MUCH more complicated and requires populating a multifarious structure to define the parameters of the new process.

So, to sum up, the reason for forking (versus exec'ing) is simplicity in creating new processes.