Reputation: 21901
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.
Upvotes: 0
Views: 1058
Reputation: 47084
How would a shell start another process, without using exec?
fork()
(or, better clone()
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 then exec()
in one of the resulting processes (which is normally the child process).
Upvotes: 6