Bash – How does exec bash builtin work internally

bashexec

From this link I get the following about exec bash builtin command:

If command is supplied, it replaces the shell without creating a
new process.

How does it exactly replace the shell (i.e. how does it work internally)? Does the exec*() system call work the same?

Best Answer

Yes, the exec builtin ultimately makes use of one of the exec*() family of system calls. So does running commands normally. It's just that when you use exec, it doesn't use the fork() system call first to create a new process, and the result is that the new command replaces the shell.

Related Question