exit 和 quick_exit 的区别
Difference between exit and quick_exit
c11标准中包含的void quick_exit( int exit_code )
和c11标准之前已经存在的void exit( int exit_code )
函数有什么区别?
quick_exit
的 Linux 手册页总结如下:
quick_exit - exits a program quickly, running minimal cleanup
The quick_exit() function exits the program quickly, calling any cleanup
functions registered with at_quick_exit(3), but not with atexit(3).
对于exit
:
exit - cause normal process termination
The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).
所以主要区别在于 quick_exit
退出时不会执行那么多清理操作。
exit
确保流缓冲区被刷新、关闭等。标准未指定 quick_exit
的此类行为。
有了这些,您可以定义两种退出应用程序的方式,一种让您在完全清理的情况下终止(由在 atexit
注册的函数创建),另一种让应用程序在不清理的情况下更快地终止很多事情(调用 at_quick_exit
注册的函数)。
在 header signal.h.
的信号处理程序中只能调用函数 _Exit、abort、signal 和 quick_exit
调用任何其他函数,如 exit
,将导致未定义的行为。
c11标准中包含的void quick_exit( int exit_code )
和c11标准之前已经存在的void exit( int exit_code )
函数有什么区别?
quick_exit
的 Linux 手册页总结如下:
quick_exit - exits a program quickly, running minimal cleanup
The quick_exit() function exits the program quickly, calling any cleanup functions registered with at_quick_exit(3), but not with atexit(3).
对于exit
:
exit - cause normal process termination
The exit() function causes normal process termination and the value of status & 0377 is returned to the parent (see wait(2)).
所以主要区别在于 quick_exit
退出时不会执行那么多清理操作。
exit
确保流缓冲区被刷新、关闭等。标准未指定 quick_exit
的此类行为。
有了这些,您可以定义两种退出应用程序的方式,一种让您在完全清理的情况下终止(由在 atexit
注册的函数创建),另一种让应用程序在不清理的情况下更快地终止很多事情(调用 at_quick_exit
注册的函数)。
在 header signal.h.
的信号处理程序中只能调用函数 _Exit、abort、signal 和quick_exit
调用任何其他函数,如 exit
,将导致未定义的行为。