A simple reference to fork()



Usage of fork()

NOTE: This reference is not an official description of fork().

Sometimes when a program has to manipulate several requests for the same part of the code it is useful to use another memory space in order to manipulate every request separetaly. In order to achieve this we use fork().

fork() returns a value of type pid_t. This value is just an unsigned int. In order to understand the usage of fork() let's imagine that we have a process. Every time we call fork() it actually creates a new child process in another place of the memory, while it returns an int to the "father" process which is actually the id number of the process created and also returns 0 to the process created ( child process ).

So checking the value that fork() returned we can continue the execution of the programm in another part of the memory for every request we have.

For a more formal and detailed description of fork() you can check the man pages of UNIX or just google it.