1ATEXIT(3P)                 POSIX Programmer's Manual                ATEXIT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       atexit — register a function to run at process termination
13

SYNOPSIS

15       #include <stdlib.h>
16
17       int atexit(void (*func)(void));
18

DESCRIPTION

20       The functionality described on this reference page is aligned with  the
21       ISO C  standard.  Any  conflict between the requirements described here
22       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
23       defers to the ISO C standard.
24
25       The  atexit()  function shall register the function pointed to by func,
26       to be called without arguments at normal program termination. At normal
27       program  termination, all functions registered by the atexit() function
28       shall be called, in the reverse order  of  their  registration,  except
29       that  a  function  is  called after any previously registered functions
30       that had already been called at the time  it  was  registered.   Normal
31       termination occurs either by a call to exit() or a return from main().
32
33       At least 32 functions can be registered with atexit().
34
35       After  a  successful  call  to any of the exec functions, any functions
36       previously registered by atexit() shall no longer be registered.
37

RETURN VALUE

39       Upon successful completion, atexit()  shall  return  0;  otherwise,  it
40       shall return a non-zero value.
41

ERRORS

43       No errors are defined.
44
45       The following sections are informative.
46

EXAMPLES

48       None.
49

APPLICATION USAGE

51       The  functions  registered  by a call to atexit() must return to ensure
52       that all registered functions are called.
53
54       The  application  should  call  sysconf()  to  obtain  the   value   of
55       {ATEXIT_MAX},  the number of functions that can be registered. There is
56       no way for an application to tell how many functions have already  been
57       registered with atexit().
58
59       Since  the  behavior is undefined if the exit() function is called more
60       than once, portable applications calling atexit() must ensure that  the
61       exit()  function  is  not called at normal process termination when all
62       functions registered by the atexit() function are called.
63
64       All functions registered by the atexit() function are called at  normal
65       process termination, which occurs by a call to the exit() function or a
66       return from main() or on the last thread termination, when the behavior
67       is  as  if  the  implementation  called  exit() with a zero argument at
68       thread termination time.
69
70       If, at  normal  process  termination,  a  function  registered  by  the
71       atexit()  function  is  called and a portable application needs to stop
72       further exit() processing, it must call the  _exit()  function  or  the
73       _Exit()  function  or one of the functions which cause abnormal process
74       termination.
75

RATIONALE

77       None.
78

FUTURE DIRECTIONS

80       None.
81

SEE ALSO

83       exec, exit(), sysconf()
84
85       The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
86
88       Portions of this text are reprinted and reproduced in  electronic  form
89       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
90       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
91       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
92       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
93       event of any discrepancy between this version and the original IEEE and
94       The Open Group Standard, the original IEEE and The Open Group  Standard
95       is  the  referee document. The original Standard can be obtained online
96       at http://www.opengroup.org/unix/online.html .
97
98       Any typographical or formatting errors that appear  in  this  page  are
99       most likely to have been introduced during the conversion of the source
100       files to man page format. To report such errors,  see  https://www.ker
101       nel.org/doc/man-pages/reporting_bugs.html .
102
103
104
105IEEE/The Open Group                  2017                           ATEXIT(3P)
Impressum