Debian Codegraph @

upstream/debian-unstable/man3/on_exit.3

raw
1 '\" t
2 .\" Copyright 1993, David Metcalfe <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH on_exit 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 on_exit \- register a function to be called at normal process termination
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <stdlib.h>
16 .P
17 .BI "int on_exit(typeof(void (int, void *)) *" function ", void *" arg );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR on_exit ():
26 .nf
27 Since glibc 2.19:
28 _DEFAULT_SOURCE
29 glibc 2.19 and earlier:
30 _BSD_SOURCE || _SVID_SOURCE
31 .fi
32 .SH DESCRIPTION
33 The
34 .BR on_exit ()
35 function registers the given
36 .I function
37 to be
38 called at normal process termination, whether via
39 .BR exit (3)
40 or via return from the program's
41 .IR main ().
42 The
43 .I function
44 is passed the status argument given to the last call to
45 .BR exit (3)
46 and the
47 .I arg
48 argument from
49 .BR on_exit ().
50 .P
51 The same function may be registered multiple times:
52 it is called once for each registration.
53 .P
54 When a child process is created via
55 .BR fork (2),
56 it inherits copies of its parent's registrations.
57 Upon a successful call to one of the
58 .BR exec (3)
59 functions, all registrations are removed.
60 .SH RETURN VALUE
61 The
62 .BR on_exit ()
63 function returns the value 0 if successful;
64 otherwise,
65 it returns a nonzero value.
66 .SH ATTRIBUTES
67 For an explanation of the terms used in this section, see
68 .BR attributes (7).
69 .TS
70 allbox;
71 lbx lb lb
72 l l l.
73 Interface Attribute Value
74 T{
75 .na
76 .nh
77 .BR on_exit ()
78 T} Thread safety MT-Safe
79 .TE
80 .SH STANDARDS
81 None.
82 .SH HISTORY
83 SunOS 4, glibc.
84 Removed in Solaris (SunOS 5).
85 Use the standard
86 .BR atexit (3)
87 instead.
88 .SH CAVEATS
89 By the time
90 .I function
91 is executed, stack
92 .RI ( auto )
93 variables may already have gone out of scope.
94 Therefore,
95 .I arg
96 should not be a pointer to a stack variable;
97 it may however be a pointer to a heap variable or a global variable.
98 .SH SEE ALSO
99 .BR _exit (2),
100 .BR atexit (3),
101 .BR exit (3)