What's a fork()
The fork() is a system call that allows the creation of multiple processes, useful for dividing tasks. For example, a network server can listen to client requests and generate a new child process to handle each request, while still maintaining the ability to listen for additional connections.
The fork() system call creates a new process (the child) that is an almost exact replica of the calling process (the parent).
The child process inherits the same memory content as the parent; however, it does not share the actual memory but rather receives a copy of it.
The new process begins execution from the first instruction following the fork() that created it. The two processes execute the same code but maintain separate copies of stack, data, heap, buffers, and I/O.
After the fork(), each process can modify variables without affecting the other process.
Subscribe to my newsletter
Read articles from Marco Mondello directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by