fork creates a new process, it is called once by the parent, but returned twice in the parent and child.
In the child process, the call to execlp executes the specified ls .
This replaces the child process with a new program file ( ls program file), which means the following.
When a process calls the execlp function or one of the other 7 exec functions, this process is completely replaced by the new program, and the new program is launched mainly by the function.
The process ID does not change to exec because a new process has not been created. exec simply replaces the current process text, data, heap and stack segments with the new program from disk.
The fork combination followed by exec is called spawning a new process on some operating systems.
Hope this was more or less clear. Let me know if you have more questions.
source share