exit(3) Library Functions Manual exit(3)

NAME

exitterminates the process

SYNOPSIS

#include <stdlib.h>

noreturn void exit(int status);

noreturn void quick_exit(int status);

noreturn void _Exit(int exitcode);

DESCRIPTION

Calling any of these three functions terminates the current process, returning the exit code passed as a parameter. The interpretation of the exit code is undefined, except that 0 or EXIT_SUCCESS shall indicate successful completion and EXIT_FAILURE shall indicate a non-successful completion.

exit() first destroys all objects with C++ thread local storage duration (the C standard leaves whether or not thread local objects are destroyed or not undefined). Next, the destructors of all C++ objects of static storage duration are invoked along with all functions passed to atexit() in reverse order of registration (the time of registration for C++ objects of static storage duration is taken to be the time at which the constructor completes). It then flushes all open FILE streams with unwritten data and closes them. Finally, files created by tmpfile() are removed, before handing control back to the host environment. Note in particular that functions registered with at_quick_exit() are not called.

quick_exit() invokes any functions registered with at_quick_exit() in reverse order of registration, then returns control to the host environment by calling _Exit(). No signal handlers are called, nor are any functions registered with atexit().

_Exit() returns control to the controlling environment without invoking any functions registered by atexit(), at_quick_exit(), any signal handlers, or the destructors of any thread local objects or C++ objects of static storage duration. Whether or not any open FILE streams with unwritten data are flushed or not is undefined.

The result of aborting a call to exit() or quick_exit() by use of longjmp() is undefined. If any function or destructor invoked by exit() or quick_exit() should throw, std::terminate() is invoked.

Undefined behaviour results if, while a call to exit() or quick_exit() is in progress, a call to exit() or quick_exit() is made.

IMPLEMENTATION NOTES

PDCLib implements the process of flushing streams in _Exit(), and therefore exit() calls it after all atexit() handlers have been invoked.

SEE ALSO

abort(3) atexit(3) at_quick_exit(3)

STANDARDS

exit() is first defined in ISO/IEC 9899:1990 (“ISO C90”); _Exit() was introduced in ISO/IEC 9899:1999 (“ISO C99”). quick_exit() was introduced in and ISO/IEC 14882:2011 "C++ 2011" .
February 20, 2013 Fusion