tags:

views:

56

answers:

1

Hi All, 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.

+6  A: 

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).

mvds
That's right, there is some kind of synergy between both syscalls. They usually are used together.
Ricardo