1ON_EXIT(3) Linux Programmer's Manual ON_EXIT(3)
2
3
4
6 on_exit - register a function to be called at normal process termina‐
7 tion
8
10 #include <stdlib.h>
11
12 int on_exit(void (*function)(int , void *), void *arg);
13
14 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
15
16 on_exit():
17 Since glibc 2.19:
18 _DEFAULT_SOURCE
19 Glibc 2.19 and earlier:
20 _BSD_SOURCE || _SVID_SOURCE
21
23 The on_exit() function registers the given function to be called at
24 normal process termination, whether via exit(3) or via return from the
25 program's main(). The function is passed the status argument given to
26 the last call to exit(3) and the arg argument from on_exit().
27
28 The same function may be registered multiple times: it is called once
29 for each registration.
30
31 When a child process is created via fork(2), it inherits copies of its
32 parent's registrations. Upon a successful call to one of the exec(3)
33 functions, all registrations are removed.
34
36 The on_exit() function returns the value 0 if successful; otherwise it
37 returns a nonzero value.
38
40 For an explanation of the terms used in this section, see at‐
41 tributes(7).
42
43 ┌──────────┬───────────────┬─────────┐
44 │Interface │ Attribute │ Value │
45 ├──────────┼───────────────┼─────────┤
46 │on_exit() │ Thread safety │ MT-Safe │
47 └──────────┴───────────────┴─────────┘
48
50 This function comes from SunOS 4, but is also present in glibc. It no
51 longer occurs in Solaris (SunOS 5). Portable application should avoid
52 this function, and use the standard atexit(3) instead.
53
55 By the time function is executed, stack (auto) variables may already
56 have gone out of scope. Therefore, arg should not be a pointer to a
57 stack variable; it may however be a pointer to a heap variable or a
58 global variable.
59
61 _exit(2), atexit(3), exit(3)
62
64 This page is part of release 5.10 of the Linux man-pages project. A
65 description of the project, information about reporting bugs, and the
66 latest version of this page, can be found at
67 https://www.kernel.org/doc/man-pages/.
68
69
70
71GNU 2019-08-02 ON_EXIT(3)