Home Explore Blog CI



man-pages

2nd chunk of `exit.man`
0208496288ebdf1a5ffa98b9094a2efcc340c948c5f6650e0000000100000b59
 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

Title: exit(3) - Standards, Notes, and Exit Status Transmission
Summary
This section details the standards to which the `exit()` function adheres (POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD). It notes undefined behavior when functions registered with `atexit(3)` or `on_exit(3)` call `exit()` or `longjmp(3)`, and that `execve(2)` removes these registrations. It recommends using `EXIT_SUCCESS` and `EXIT_FAILURE` for better portability. It also discusses how the exit status is transmitted to the parent process, covering scenarios with `SA_NOCLDWAIT`, `SIGCHLD`, and when the parent is waiting on the child.