exit(3) Library Functions Manual exit(3)
NAME
exit - cause normal process termination
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
[[noreturn]] void exit(int status);
DESCRIPTION
The exit() function causes normal process termination and the least significant byte of status (i.e., status & 0xFF) is returned to the parent (see wait(2)).
All functions registered with atexit(3) and on_exit(3) are called, in the reverse order of their registration. (It is possible for one of these functions to use atexit(3) or on_exit(3) to register an additional func‐
tion to be executed during exit processing; the new registration is added to the front of the list of functions that remain to be called.) If one of these functions does not return (e.g., it calls _exit(2), or kills
itself with a signal), then none of the remaining functions is called, and further exit processing (in particular, flushing of stdio(3) streams) is abandoned. If a function has been registered multiple times using
atexit(3) or on_exit(3), then it is called as many times as it was registered.
All open stdio(3) streams are flushed and closed. Files created by tmpfile(3) are removed.
The C standard specifies two constants, EXIT_SUCCESS and EXIT_FAILURE, that may be passed to exit() to indicate successful or unsuccessful termination, respectively.
RETURN VALUE
The exit() function does not return.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────────────┬─────────────────────┐
│ Interface │ Attribute │ Value │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼───────────────┼─────────────────────┤
│ exit() │ Thread safety │ MT‐Unsafe race:exit │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────────────┴─────────────────────┘
The exit() function uses a global variable that is not protected, so it is not thread‐safe.
STANDARDS