gpt4 book ai didi

exit - libc.so 中的 exit 和 _exit 有什么区别?

转载 作者:行者123 更新时间:2023-12-05 01:48:51 28 4
gpt4 key购买 nike

(gdb) info symbol exit
exit in section .text of /lib64/libc.so.6
(gdb) info symbol _exit
_exit in section .text of /lib64/libc.so.6

有人知道吗?

最佳答案

简单地说,exit 是一个高级函数,您应该调用它来退出进程,它会调用退出处理程序和一些其他高级清理内容。 _exit 是一个低级清理函数,它被称为 exit 的最后一步。 exit 将真正终止进程(通过 exit 系统调用)。

来自 glibc 手册在http://www.gnu.org/software/libc/manual/html_mono/libc.html (详情请查看 glibc 的源代码):

25.6.1 Normal Termination

A process terminates normally when its program signals it is done by calling exit. Returning from main is equivalent to calling exit, and the value that main returns is used as the argument to exit.

— Function: void exit (int status)

The exit function tells the system that the program is done, which causes it to terminate the process.

status is the program's exit status, which becomes part of the process' termination status. This function does not return.

Normal termination causes the following actions:

Functions that were registered with the atexit or on_exit functions are called in the reverse order of their registration. This mechanism allows your application to specify its own “cleanup” actions to be performed at program termination. Typically, this is used to do things like saving program state information in a file, or unlocking locks in shared data bases.

All open streams are closed, writing out any buffered output data. See Closing Streams. In addition, temporary files opened with the tmpfile function are removed; see Temporary Files.

_exit is called, terminating the program. See Termination Internals.

在“终止内部”部分:

25.6.5 Termination Internals

The _exit function is the primitive used for process termination by exit. It is declared in the header file unistd.h.

— Function: void _exit (int status)

The _exit function is the primitive for causing a process to terminate with status status. Calling this function does not execute cleanup functions registered with atexit or on_exit.

关于exit - libc.so 中的 exit 和 _exit 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5576549/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com