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