更新时间:2022-12-08 20:52:24
系统()
召唤出 SH
处理您的命令行,这样你就可以得到通配符扩展等执行exec()
和它的朋友请更换一个新的进程映像当前的进程映像。
system()
calls out to sh
to handle your command line, so you can get wildcard expansion, etc. exec()
and its friends replace the current process image with a new process image.
使用系统()
,你的程序继续运行,你回来你调用的外部命令的一些状态。随着执行exec()
,你的进程抹杀。
With system()
, your program continues running and you get back some status about the external command you called. With exec()
, your process is obliterated.
在一般情况下,我想你能想到的系统()
作为更高层次的接口。你可以重复使用一些组合自己的功能叉()
,执行exec()
和等待()
。
In general, I guess you could think of system()
as a higher-level interface. You could duplicate its functionality yourself using some combination fork()
, exec()
, and wait()
.
要回答你的最后一个问题,系统()
导致创建一个子进程,并在执行exec()
家庭没有。您需要使用叉()
为
To answer your final question, system()
causes a child process to be created, and the exec()
family do not. You would need to use fork()
for that.