请问exit与_exit的区别?

dongjiawei316 2009-07-01 10:35:28
如题!
...全文
160 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangfeng999 2009-07-02
  • 打赏
  • 举报
回复
详见AUPE8.5
Executing a return from the main function. As we saw in Section 7.3, this is equivalent to calling exit.

Calling the exit function. This function is defined by ISO C and includes the calling of all exit handlers that have been registered by calling atexit and closing all standard I/O streams. Because ISO C does not deal with file descriptors, multiple processes (parents and children), and job control, the definition of this function is incomplete for a UNIX system.

Calling the _exit or _Exit function. ISO C defines _Exit to provide a way for a process to terminate without running exit handlers or signal handlers. Whether or not standard I/O streams are flushed depends on the implementation. On UNIX systems, _Exit and _exit are synonymous and do not flush standard I/O streams. The _exit function is called by exit and handles the UNIX system-specific details; _exit is specified by POSIX.1.

In most UNIX system implementations, exit(3) is a function in the standard C library, whereas _exit(2) is a system call.

Executing a return from the start routine of the last thread in the process. The return value of the thread is not used as the return value of the process, however. When the last thread returns from its start routine, the process exits with a termination status of 0.

Calling the pthread_exit function from the last thread in the process. As with the previous case, the exit status of the process in this situation is always 0, regardless of the argument passed to pthread_exit. We'll say more about pthread_exit in Section 11.5.

mengjfu 2009-07-02
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mymtom 的回复:]
exit是C标准库函数,调用atexit注册的函数,刷新文件缓冲区,并关闭之,删除用tmpfile建立的文件
然后调用_exit()结束进程
_exit是Unix系统调用。
C99还有个_Exit(), 不调用atexit注册的函数,其他几项清理工作可能全做,可能全不做,也可能不全做,取决于实现。
[/Quote]
正解
坚强的豁着 2009-07-01
  • 打赏
  • 举报
回复
-exit直接使进程停止运行,exit则停止时做一些工作
mymtom 2009-07-01
  • 打赏
  • 举报
回复
exit是C标准库函数,调用atexit注册的函数,刷新文件缓冲区,并关闭之,删除用tmpfile建立的文件
然后调用_exit()结束进程
_exit是Unix系统调用。
C99还有个_Exit(), 不调用atexit注册的函数,其他几项清理工作可能全做,可能全不做,也可能不全做,取决于实现。

23,120

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧