]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/on_exit.3
All pages: Replace the 4th argument to .TH by "Linux man-pages (unreleased)"
[thirdparty/man-pages.git] / man3 / on_exit.3
CommitLineData
fea681da
MK
1.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
fea681da
MK
4.\"
5.\" References consulted:
6.\" Linux libc source code
7.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
8.\" 386BSD man pages
9.\" Modified 1993-04-02, David Metcalfe
10.\" Modified 1993-07-25, Rik Faith (faith@cs.unc.edu)
7bd6328f 11.TH ON_EXIT 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
fea681da 12.SH NAME
027df6e0 13on_exit \- register a function to be called at normal process termination
06a705b1
AC
14.SH LIBRARY
15Standard C library
8fc3b2cf 16.RI ( libc ", " \-lc )
fea681da
MK
17.SH SYNOPSIS
18.nf
19.B #include <stdlib.h>
68e4db0a 20.PP
d62694cc 21.BI "int on_exit(void (*" function ")(int, void *), void *" arg );
fea681da 22.fi
68e4db0a 23.PP
d39ad78f 24.RS -4
cc4615cc
MK
25Feature Test Macro Requirements for glibc (see
26.BR feature_test_macros (7)):
d39ad78f 27.RE
68e4db0a 28.PP
cc4615cc 29.BR on_exit ():
9d281e06 30.nf
51c612fb
MK
31 Since glibc 2.19:
32 _DEFAULT_SOURCE
33 Glibc 2.19 and earlier:
34 _BSD_SOURCE || _SVID_SOURCE
9d281e06 35.fi
fea681da 36.SH DESCRIPTION
60a90ecd
MK
37The
38.BR on_exit ()
c6fa0841
MK
39function registers the given
40.I function
41to be
027df6e0 42called at normal process termination, whether via
fea681da 43.BR exit (3)
c6fa0841
MK
44or via return from the program's
45.IR main ().
46The
47.I function
48is passed the status argument given to the last call to
fea681da 49.BR exit (3)
c6fa0841
MK
50and the
51.I arg
52argument from
60a90ecd 53.BR on_exit ().
847e0d88 54.PP
6a275cde
MK
55The same function may be registered multiple times:
56it is called once for each registration.
847e0d88 57.PP
36a0cc25
MK
58When a child process is created via
59.BR fork (2),
60it inherits copies of its parent's registrations.
61Upon a successful call to one of the
62.BR exec (3)
63functions, all registrations are removed.
47297adb 64.SH RETURN VALUE
60a90ecd
MK
65The
66.BR on_exit ()
67function returns the value 0 if successful; otherwise
c7094399 68it returns a nonzero value.
d388b47f
ZL
69.SH ATTRIBUTES
70For an explanation of the terms used in this section, see
71.BR attributes (7).
c466875e
MK
72.ad l
73.nh
d388b47f
ZL
74.TS
75allbox;
c466875e 76lbx lb lb
d388b47f
ZL
77l l l.
78Interface Attribute Value
79T{
80.BR on_exit ()
81T} Thread safety MT-Safe
82.TE
c466875e
MK
83.hy
84.ad
847e0d88 85.sp 1
3113c7f3 86.SH STANDARDS
a4b636a0 87This function comes from SunOS 4, but is also present in glibc.
68e1685c 88It no longer occurs in Solaris (SunOS 5).
4ccc3a14 89Portable application should avoid this function, and use the standard
fea681da
MK
90.BR atexit (3)
91instead.
7c17e8f3
MK
92.SH NOTES
93By the time
94.I function
95is executed, stack
96.RI ( auto )
97variables may already have gone out of scope.
98Therefore,
99.I arg
100should not be a pointer to a stack variable;
101it may however be a pointer to a heap variable or a global variable.
47297adb 102.SH SEE ALSO
c62b9eaa 103.BR _exit (2),
fea681da
MK
104.BR atexit (3),
105.BR exit (3)