I am looking for a real world scenerio where using exec will be the only availble option ( The problem could not be solved if exec is not used)
I know what is exec and how it differs from fork, but still intrested in real world problem that enforce the use of exec command.
How would a shell start another process, without using exec?
fork()(or, betterclone()nowadays, on Linux) just says to duplicate a process. So then you have 2 copies of the same process.execve()(and -le, -lp, -vp, -v friends) just says to replace the current process entirely with a new process. (keeping the fd’s, but not much more)So to fire another program, you must first
fork()and thenexec()in one of the resulting processes (which is normally the child process).