为什么execv退出功能? [英] Why does execv exit a function?
问题描述
这是Unix v6代码: http://v6shell.org/history/if.c
Here is the unix v6 code: http://v6shell.org/history/if.c
doex(earg) {
...
execv(ncom, nargv, np);
return(1);
}
因此,如果execv成功执行,我们将不会到达下一行并返回1.相反,execv将返回值(0?)并退出函数doex. 但是为什么?
So if execv is successfully executed, we will not reach the next line and return 1. Instead execv will return something (0?) and exit the function doex. But why?
除了您必须编写以下内容外,我会这样做:
I would except you would have to write this:
if ( execv(ncom, nargv, np) ) return (0);
return (1);
unix v6执行程序-手册页: http://man.cat-v .org/unix-6th/2/exec
unix v6 exec - man page: http://man.cat-v.org/unix-6th/2/exec
推荐答案
从所链接的exec
手册页的开头:
From the start of the exec
man page you linked:
Exec用命名文件覆盖调用过程,然后 传输到文件核心映像的开头. 文件中没有退货;调用核心图像 迷路了.
Exec overlays the calling process with the named file, then transfers to the beginning of the core image of the file. There can be no return from the file; the calling core image is lost.
就像今天的exec
函数一样,execv
由于某种原因失败,则控制权将传递到下一行,并且该函数将成为return 1
.否则,子流程的退出代码将用作该流程的退出代码,并且该流程中的其他代码将不再执行.
Just like in today's exec
functions, the execv
call fully replaces the calling process with a new one. If execv
failed for some reason, control will pass to the next line and the function will return 1
. Otherwise, the exit code of the subprocess will be used as the exit code of this process, and no further code from this process will execute.
这篇关于为什么execv退出功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!