]>
Commit | Line | Data |
---|---|---|
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 | 13 | on_exit \- register a function to be called at normal process termination |
06a705b1 AC |
14 | .SH LIBRARY |
15 | Standard 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 |
25 | Feature 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 |
37 | The |
38 | .BR on_exit () | |
c6fa0841 MK |
39 | function registers the given |
40 | .I function | |
41 | to be | |
027df6e0 | 42 | called at normal process termination, whether via |
fea681da | 43 | .BR exit (3) |
c6fa0841 MK |
44 | or via return from the program's |
45 | .IR main (). | |
46 | The | |
47 | .I function | |
48 | is passed the status argument given to the last call to | |
fea681da | 49 | .BR exit (3) |
c6fa0841 MK |
50 | and the |
51 | .I arg | |
52 | argument from | |
60a90ecd | 53 | .BR on_exit (). |
847e0d88 | 54 | .PP |
6a275cde MK |
55 | The same function may be registered multiple times: |
56 | it is called once for each registration. | |
847e0d88 | 57 | .PP |
36a0cc25 MK |
58 | When a child process is created via |
59 | .BR fork (2), | |
60 | it inherits copies of its parent's registrations. | |
61 | Upon a successful call to one of the | |
62 | .BR exec (3) | |
63 | functions, all registrations are removed. | |
47297adb | 64 | .SH RETURN VALUE |
60a90ecd MK |
65 | The |
66 | .BR on_exit () | |
67 | function returns the value 0 if successful; otherwise | |
c7094399 | 68 | it returns a nonzero value. |
d388b47f ZL |
69 | .SH ATTRIBUTES |
70 | For 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 |
75 | allbox; | |
c466875e | 76 | lbx lb lb |
d388b47f ZL |
77 | l l l. |
78 | Interface Attribute Value | |
79 | T{ | |
80 | .BR on_exit () | |
81 | T} Thread safety MT-Safe | |
82 | .TE | |
c466875e MK |
83 | .hy |
84 | .ad | |
847e0d88 | 85 | .sp 1 |
3113c7f3 | 86 | .SH STANDARDS |
a4b636a0 | 87 | This function comes from SunOS 4, but is also present in glibc. |
68e1685c | 88 | It no longer occurs in Solaris (SunOS 5). |
4ccc3a14 | 89 | Portable application should avoid this function, and use the standard |
fea681da MK |
90 | .BR atexit (3) |
91 | instead. | |
7c17e8f3 MK |
92 | .SH NOTES |
93 | By the time | |
94 | .I function | |
95 | is executed, stack | |
96 | .RI ( auto ) | |
97 | variables may already have gone out of scope. | |
98 | Therefore, | |
99 | .I arg | |
100 | should not be a pointer to a stack variable; | |
101 | it 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) |