考虑以下代码:
close(channel_data->pty_master);
if (login_tty(channel_data->pty_slave) != 0) // new terminal session
{
exit(1); // fail
}
execl("/bin/sh", "sh", mode, command, NULL); // replace process image
exit(0);
根据 execl()
的文档,当前进程镜像正在被替换,调用仅在出错时返回。
但是,如果过程镜像被替换,为什么在调用 execl()
之后调用 exit()
?
最佳答案
Exec 调用可能会失败。一个常见的结语是:
perror("Some eror message");
_exit(127); /*or _exit(1); (127 is what shells return) */
您通常会在此处运行 _exit
而不是 exit
,以便跳过 atexit
Hook 和 stdio
缓冲区冲洗。
关于c - 在调用 execl() 之后退出 (0) 是否有意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45350281/