c - 在调用 execl() 之后退出 (0) 是否有意义?

标签 c linux

考虑以下代码:

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/

相关文章:

c - -O0 处的内联函数导致 clang 中的链接失败

linux - 用jvm启动tomcat

c++ - ubuntu 18.04 上的 gcc/g++ 7.3.0 链接错误

linux - 如何理解内核中 "page_align"的宏?

linux - ALSA 音频和 YouTube

c - 在出列之前返回链表中的第一个元素时出现问题

c - scanf格式字符串中不同位置的空格有何影响?

ruby-on-rails - 从 Rails 应用程序运行 shell 脚本,无论最终用户如何,它都能正常工作吗?

c - 在使用#ifndef 的#undef 之后#define 没有按预期工作

C 中的损坏堆,我不知道为什么