When a user forks, initially both the processes are using the same address space, whereas when we use exec, it makes the child process switch to a completely new address space i.e. the address space is same but everything is newly allocated for it.
Few reasons why we use exec funcions *To replace the current process * To reuse the current process' resources and PID *In Linux every functions calls the execve(which is a exec family) function which is actually understood by the kernel, this is because to reuse the current process context(which is the bash shell) for the further processes.
The execl() is used to replace the current working process with the new one.
It is used for Reuse process context. the current process context (such as open files, file descriptors, and environment variables) is retained, but the program code, data, and stack are replaced with the new program.
Instead of creating a completely new process, exec() just loads new program into the existing process ID (PID) remains the same,avoiding the need for an additional forked process in certain situations.