1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" References consulted:
26 .\" Linux libc source code
27 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\" Modified 1993-03-29, David Metcalfe
30 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2003-10-25, Walter Harms
33 .TH ATEXIT 3 2008-12-05 "Linux" "Linux Programmer's Manual"
35 atexit \- register a function to be called at normal process termination
38 .B #include <stdlib.h>
40 .BI "int atexit(void (*" function )(void));
45 function registers the given
48 called at normal process termination, either via
50 or via return from the program's
52 Functions so registered are called in
53 the reverse order of their registration; no arguments are passed.
55 The same function may be registered multiple times:
56 it is called once for each registration.
58 POSIX.1-2001 requires that an implementation allow at least
60 (32) such functions to be registered.
61 The actual limit supported by an implementation can be obtained using
64 When a child process is created via
66 it inherits copies of its parent's registrations.
67 Upon a successful call to one of the
70 all registrations are removed.
74 function returns the value 0 if successful; otherwise
75 it returns a nonzero value.
77 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
79 Functions registered using
83 are not called if a process terminates abnormally because
84 of the delivery of a signal.
86 If one of the functions registered functions calls
88 then any remaining functions are not invoked,
89 and the other process termination steps performed by
93 POSIX.1-2001 says that the result of calling
95 more than once (i.e., calling
97 within a function registered using
100 On some systems (but not Linux), this can result in an infinite recursion;
101 .\" This can happen on OpenBSD 4.2 for example, and is documented
102 .\" as occurring on FreeBSD as well.
103 .\" Glibc does "the Right Thing" -- invocation of the remaining
104 .\" exit handlers carries on as normal.
105 portable programs should not invoke
107 inside a function registered using
114 functions register functions on the same list:
115 at normal process termination,
116 the registered functions are invoked in reverse order
117 of their registration by these two functions.
119 POSIX.1-2001 says that the result is undefined if
121 is used to terminate execution of one of the functions registered
123 .\" In glibc, things seem to be handled okay
129 can be used within a shared library to establish functions
130 that are called when the shared library is unloaded.
140 printf("That was all, folks\en");
149 a = sysconf(_SC_ATEXIT_MAX);
150 printf("ATEXIT_MAX = %ld\en", a);
154 fprintf(stderr, "cannot set exit function\en");
166 This page is part of release 3.67 of the Linux
169 A description of the project,
170 information about reporting bugs,
171 and the latest version of this page,
173 \%http://www.kernel.org/doc/man\-pages/.