how does execlp() system call work? how does execlp() system call work? unix unix

how does execlp() system call work?


fork creates a new process, it is called once by the parent but returns twice in the parent and in the child.

In the child process the call execlp executes the specified command ls.

This replaces the child process with the new program file (ls program file) which means following.

When a process calls the execlp or one of the other 7 exec functions, that process is completely replaced by the new program, and the new program starts executing at its mainfunction.

The process ID does not change across an exec, because a new process is notcreated. exec merely replaces the current process's text, data, heap, and stacksegments with a brand new program from disk.

The combination of fork followed by exec is called spawning a new process on some operating systems.

Hopefully it was more or less clear. Let me know if you have more questions.


The exec() family of functions replaces the current process image with a new process image.