1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified 1993-03-29, David Metcalfe
28 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
29 .\" Modified 2003-10-25, Walter Harms
31 .TH ATEXIT 3 2003-11-01 "" "Linux Programmer's Manual"
33 atexit \- register a function to be called at normal process termination
36 .B #include <stdlib.h>
38 .BI "int atexit(void (*" function )(void));
41 The \fBatexit\fP() function registers the given \fIfunction\fP to be
42 called at normal process termination, either via
44 or via return from the program's \fImain\fP().
45 Functions so registered are called in
46 the reverse order of their registration; no arguments are passed.
48 POSIX.1-2001 requires that an implementation allow at least ATEXIT_MAX (32)
49 such functions to be registered.
50 The actual limit supported by an implementation can be obtained using
53 When a child process is created via
55 it inherits copies of the its parents registrations.
56 Upon a successful call to one of the
59 all registrations are removed.
61 The \fBatexit\fP() function returns the value 0 if successful; otherwise
62 it returns a non-zero value.
70 printf("That was all, folks\en");
77 a = sysconf(_SC_ATEXIT_MAX);
78 printf("ATEXIT_MAX = %ld\en", a);
82 fprintf(stderr, "cannot set exit function\en");
89 Since glibc 2.2.3, \fBatexit\fP() (and \fBon_exit\fP())
90 can be used to within a shared library to establish functions
91 that are called when the shared library is unloaded.
93 Functions registered using \fBatexit\fP() (and \fBon_exit\fP())
94 are not called if a process terminates abnormally because
95 of the delivery of a signal.
97 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.