1on_exit(3)                 Library Functions Manual                 on_exit(3)
2
3
4

NAME

6       on_exit  -  register a function to be called at normal process termina‐
7       tion
8

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <stdlib.h>
14
15       int on_exit(void (*function)(int, void *), void *arg);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       on_exit():
20           Since glibc 2.19:
21               _DEFAULT_SOURCE
22           glibc 2.19 and earlier:
23               _BSD_SOURCE || _SVID_SOURCE
24

DESCRIPTION

26       The on_exit() function registers the given function  to  be  called  at
27       normal  process termination, whether via exit(3) or via return from the
28       program's main().  The function is passed the status argument given  to
29       the last call to exit(3) and the arg argument from on_exit().
30
31       The  same  function may be registered multiple times: it is called once
32       for each registration.
33
34       When a child process is created via fork(2), it inherits copies of  its
35       parent's  registrations.   Upon a successful call to one of the exec(3)
36       functions, all registrations are removed.
37

RETURN VALUE

39       The on_exit() function returns the value 0 if successful; otherwise  it
40       returns a nonzero value.
41

ATTRIBUTES

43       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
44       tributes(7).
45
46       ┌────────────────────────────────────────────┬───────────────┬─────────┐
47Interface                                   Attribute     Value   
48       ├────────────────────────────────────────────┼───────────────┼─────────┤
49on_exit()                                   │ Thread safety │ MT-Safe │
50       └────────────────────────────────────────────┴───────────────┴─────────┘
51

STANDARDS

53       None.
54

HISTORY

56       SunOS 4, glibc.  Removed in Solaris (SunOS 5).  Use the standard  atex‐
57       it(3) instead.
58

CAVEATS

60       By  the  time  function is executed, stack (auto) variables may already
61       have gone out of scope.  Therefore, arg should not be a  pointer  to  a
62       stack  variable;  it  may  however be a pointer to a heap variable or a
63       global variable.
64

SEE ALSO

66       _exit(2), atexit(3), exit(3)
67
68
69
70Linux man-pages 6.04              2023-03-30                        on_exit(3)
Impressum