C 中的退出函数

发布于 2024-09-18 12:40:24 字数 255 浏览 3 评论 0原文

C中的exit()_exit()_Exit()有什么区别?

我如何决定使用哪个?

在狂欢节上,

人2退出

给了我页面 _EXIT(2),而

人3退出

给出了页面 EXIT(3)。

What is the difference between exit(), _exit() and _Exit() in C?

How do I decide which to use?

On bash,

man 2 exit

gave me the page _EXIT(2), whereas

man 3 exit

gave the page EXIT(3).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

慕巷 2024-09-25 12:40:24

exit() 清理后终止。

_exit() 调用后立即终止。

如果在调用exit()函数时有一些堆栈损坏,程序可能会因分段错误而关闭,如果您使用_exit(),程序会以快速模式退出。

来自 http://msdn.microsoft.com/en-us/library/6wdz5232 .aspx 你有

exit() - 执行完整的 C 库终止过程,终止进程,并使用提供的状态代码退出。

_exit() - 执行快速 C 库终止过程,终止进程,并使用提供的状态代码退出。

_cexit() - 执行完整的 C 库终止过程并返回给调用者,但不终止进程。

_c_exit() - 执行快速 C 库终止过程并返回给调用者,但不终止进程。

exit() terminating after cleanup.

_exit() terminating immediately after call.

If you have some stack corrupted while exit() function was called program may close with Segmentation Fault, if you are use _exit(), program exit in quick mode.

From http://msdn.microsoft.com/en-us/library/6wdz5232.aspx you have

exit() - Performs complete C library termination procedures, terminates the process, and exits with the supplied status code.

_exit() - Performs quick C library termination procedures, terminates the process, and exits with the supplied status code.

_cexit() - Performs complete C library termination procedures and returns to the caller, but does not terminate the process.

_c_exit() - Performs quick C library termination procedures and returns to the caller, but does not terminate the process.

焚却相思 2024-09-25 12:40:24

C99 中的规范是 exit_Exit

两者之间的区别在于 exit 还执行可能使用 atexit 注册的处理程序并关闭流等,而 _Exit 不调用atexit 例程,可能会也可能不会正确关闭流。

_exit 来自 POSIX,与 _Exit 具有相似的属性,不同之处在于它保证正确关闭流。

总之,只要有可能,您就应该使用 exit,这是最干净的终止方式。

Normative in C99 are exit and _Exit.

The difference between the two is that exit also executes the handlers that may be registered with atexit and closes streams etc whereas _Exit doesn't call the atexit routines and may or may not close streams properly.

_exit is from POSIX and has similar properties as _Exit with the difference that it is guaranteed to close streams properly.

In summary, whenever you can you should use exit, this is the cleanest way to terminate.

长伴 2024-09-25 12:40:24

来自男人:

exit:
调用所有用atexit(3)和on_exit(3)注册的函数,在
它们的注册顺序相反...所有打开的 stdio(3) 流都被刷新并关闭。 tmpfile(3) 创建的文件将被删除。

_exit:
函数_exit()类似于exit(3),但不调用任何函数
使用 atexit(3) 或 on_exit(3) 注册。是否冲水标准
I/O 缓冲并删除使用 tmpfile(3) 创建的临时文件
取决于实施。另一方面,_exit() 确实关闭打开
文件描述符...

From man:

exit:
All functions registered with atexit(3) and on_exit(3) are called, in
the reverse order of their registration ... All open stdio(3) streams are flushed and closed. Files created by tmpfile(3) are removed.

_exit:
The function _exit() is like exit(3), but does not call any functions
registered with atexit(3) or on_exit(3). Whether it flushes standard
I/O buffers and removes temporary files created with tmpfile(3) is
implementation-dependent. On the other hand, _exit() does close open
file descriptors ...

2024-09-25 12:40:24

1.退出():
它正在清理关闭文件描述符、文件流等工作,
2._exit() :
它不是清理诸如关闭文件描述符、文件流等工作。

这些是 exit() 和 _exit() 的主要区别。

我纠正你的答案了吗

1.exit() :
it's cleanup the work like closing file descriptor, file stream and so on,
2._exit() :
it's not cleanup the work like closing the file descriptor,file stream and so on

These are the major difference of exit() and _exit().

am i rectified ur answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文