fork() and exec(): The Weird and Elegant Idea Behind Unix Process Creation
At first glance, Unix’s fork() + exec() model feels… wrong. Why would an operating system copy an entire process, only to immediately replace it with something else? It seems wasteful, indirect, an...

Source: DEV Community
At first glance, Unix’s fork() + exec() model feels… wrong. Why would an operating system copy an entire process, only to immediately replace it with something else? It seems wasteful, indirect, and unnecessarily complicated. And yet, this design has survived for over 50 years, and still powers modern systems today. In this post, we’ll explore what fork() and exec() actually do, why this design exists, and why it remains so hard to replace. fork() fork() is a system call in POSIX operating systems. It creates an almost exact replica of the process that calls it. The calling process is known as the parent, and the new one is the child. fork() takes no arguments and returns the PID of the child to the parent and 0 to the child. This return value is used to determine whether a process is the parent or the child. When fork() was first introduced, the parent and child ran in separate memory spaces with identical contents. This was expensive, especially for large processes with large memory