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
11

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

49       None.
50

APPLICATION USAGE

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

RATIONALE

78       None.
79

FUTURE DIRECTIONS

81       None.
82

SEE ALSO

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