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
POSIX.1‐2001, POSIX.1‐2008, C99, SVr4, 4.3BSD.
NOTES
The behavior is undefined if one of the functions registered using atexit(3) and on_exit(3) calls either exit() or longjmp(3). Note that a call to execve(2) removes registrations created using atexit(3) and on_ex‐
it(3).
The use of EXIT_SUCCESS and EXIT_FAILURE is slightly more portable (to non‐UNIX environments) than the use of 0 and some nonzero value like 1 or -1. In particular, VMS uses a different convention.
BSD has attempted to standardize exit codes (which some C libraries such as the GNU C library have also adopted); see the file <sysexits.h>.
After exit(), the exit status must be transmitted to the parent process. There are three cases:
• If the parent has set SA_NOCLDWAIT, or has set the SIGCHLD handler to SIG_IGN, the status is discarded and the child dies immediately.
• If the parent was waiting on the child, it is notified of the exit status and the child