C 中的退出函数
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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.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 withatexit
and closes streams etc whereas_Exit
doesn't call theatexit
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.来自男人:
From man:
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