What if your computer could start new programs all by itself, instantly and without mistakes?
Why Process creation (fork and exec) in Operating Systems? - Purpose & Use Cases
Imagine you want your computer to run two programs at the same time, but you have to start each one by typing commands manually every time.
You open a terminal, run one program, then close it, then open another terminal and run the next program.
This manual way is slow and tiring because you must do everything step-by-step.
It's easy to make mistakes like typing wrong commands or forgetting to start a program.
You also can't easily make programs start other programs automatically.
Process creation using fork and exec lets the computer copy a running program and then replace the copy with a new program.
This means one program can create another program to run without you typing commands again.
It makes multitasking smooth and automatic.
Run program A Close program A Run program B
pid = fork() if pid == 0: exec('programB')
It enables programs to start other programs automatically, making multitasking and complex workflows possible.
Your web browser opens a new tab by creating a new process to load a webpage without stopping the browser itself.
Manual program starting is slow and error-prone.
Fork creates a copy of a running program.
Exec replaces the copy with a new program to run.