开发者

Difference b/w exec( ) and system( ) in unix

What is exactly the difference between commands exec(const char *c) and system(const char *c) in unix based systems ?

Both can be called fro开发者_如何学编程m a C program to execute system calls. Is there a difference b/w the two ?


exec replaces your process with the specified program. Your program is done, and will not continue running.

spawn starts a new process (probably by first using fork), and runs the specified program while your program continues executing.

system starts a new process (probably by first using fork), and runs the specified program while your program waits. Once the child exits, your program continues.


exec will execute a file, while system will execute a shell and feed it with the arguments.

From wikipedia:

It (system) differs from the exec/spawn family of functions in that instead of passing arguments to an executed object, a single string is passed to the system shell, typically the POSIX shell, /bin/sh -c.

http://en.wikipedia.org/wiki/System_%28C_standard_library%29

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜