Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated references and clarified POSIX guarantees.

...

Wiki Markup
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="4e8ea2ad37b8e0af-fac12812-4ad345de-bddaa7c0-7bb98c9224e29e73d58b5549"><ac:parameter ac:name="">1</ac:parameter></ac:structured-macro>\[1\] Note that POSIX ^®^ strengthens the specification for {{_Exit()}} by prohibiting the function from flushing stream buffers. See the {{[documentation|http://www.opengroup.org/onlinepubs/9699919799/functions/_Exit.html]}} of the function in \[\[OpenIEEE Group 08\]Std 1003.1-2008|AA. References#OpenReferences#IEEE Group 08Std 1003.1-2008]\].

Code Block
bgColor#ccccff
#include <stdlib.h>
/* ... */

if (/* something really bad happened */) {
  _Exit(EXIT_FAILURE);
}

...

As with _Exit(), whether open streams with unwritten buffered data are flushed #2, open streams are closed #2, or temporary files are removed is implementation-defined. Functions registered by atexit() are not executed (see ERR06-C. Understand the termination behavior of assert() and abort()).

Wiki Markup
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="134b506b115ac9d9-bdbae024-43474e03-9a11a1d7-773e3cc28451903d5644c496"><ac:parameter ac:name="">2</ac:parameter></ac:structured-macro>\[2\] Unlike in the case of {{\_Exit()}}, POSIX ^®^ explicitly permits but does not require implementations to flush stream buffers. See the {{[documentation|http://www.opengroup.org/onlinepubs/9699919799/functions/abort.html]}} of the function in \[\[OpenIEEE Group 08\]Std 1003.1-2008|AA. References#OpenReferences#IEEE Group 08Std 1003.1-2008]\].

Summary

The following table summarizes the exit behavior of the program termination functions.

Function

Closes
Open
streams

Flushes
Stream
Buffers

Removes
Temporary
Files

Calls
atexit()
Handlers

Program
Termination

abort()

(info)

(info) #2

(info)

(error)

abnormal

_Exit()

(info)

(info) #1

(info)

(error)

normal

exit()

(tick)

(tick)

(tick)

(tick)

normal

return from main()

(tick)

(tick)

(tick)

(tick)

normal

...