]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/on_exit.3
err.3: EXAMPLES: use EXIT_FAILURE rather than 1 as exit status
[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)
63121bd4 31.TH ON_EXIT 3 2019-08-02 "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
fea681da
MK
38.BI "int on_exit(void (*" function ")(int , void *), void *" arg );
39.fi
68e4db0a 40.PP
cc4615cc
MK
41.in -4n
42Feature Test Macro Requirements for glibc (see
43.BR feature_test_macros (7)):
44.in
68e4db0a 45.PP
cc4615cc 46.BR on_exit ():
51c612fb
MK
47 Since glibc 2.19:
48 _DEFAULT_SOURCE
49 Glibc 2.19 and earlier:
50 _BSD_SOURCE || _SVID_SOURCE
fea681da 51.SH DESCRIPTION
60a90ecd
MK
52The
53.BR on_exit ()
c6fa0841
MK
54function registers the given
55.I function
56to be
027df6e0 57called at normal process termination, whether via
fea681da 58.BR exit (3)
c6fa0841
MK
59or via return from the program's
60.IR main ().
61The
62.I function
63is passed the status argument given to the last call to
fea681da 64.BR exit (3)
c6fa0841
MK
65and the
66.I arg
67argument from
60a90ecd 68.BR on_exit ().
847e0d88 69.PP
6a275cde
MK
70The same function may be registered multiple times:
71it is called once for each registration.
847e0d88 72.PP
36a0cc25
MK
73When a child process is created via
74.BR fork (2),
75it inherits copies of its parent's registrations.
76Upon a successful call to one of the
77.BR exec (3)
78functions, all registrations are removed.
47297adb 79.SH RETURN VALUE
60a90ecd
MK
80The
81.BR on_exit ()
82function returns the value 0 if successful; otherwise
c7094399 83it returns a nonzero value.
d388b47f
ZL
84.SH ATTRIBUTES
85For an explanation of the terms used in this section, see
86.BR attributes (7).
87.TS
88allbox;
89lb lb lb
90l l l.
91Interface Attribute Value
92T{
93.BR on_exit ()
94T} Thread safety MT-Safe
95.TE
847e0d88 96.sp 1
47297adb 97.SH CONFORMING TO
a4b636a0 98This function comes from SunOS 4, but is also present in glibc.
68e1685c 99It no longer occurs in Solaris (SunOS 5).
4ccc3a14 100Portable application should avoid this function, and use the standard
fea681da
MK
101.BR atexit (3)
102instead.
7c17e8f3
MK
103.SH NOTES
104By the time
105.I function
106is executed, stack
107.RI ( auto )
108variables may already have gone out of scope.
109Therefore,
110.I arg
111should not be a pointer to a stack variable;
112it may however be a pointer to a heap variable or a global variable.
47297adb 113.SH SEE ALSO
c62b9eaa 114.BR _exit (2),
fea681da
MK
115.BR atexit (3),
116.BR exit (3)