]> pd.if.org Git - pdclib/blob - man3/atexit.3
Cosmetic comment fixes.
[pdclib] / man3 / atexit.3
1 .\" This file is part of the Public Domain C Library (PDCLib).
2 .\" Permission is granted to use, modify, and / or redistribute at will.
3 .\"
4 .Dd
5 .Dt atexit 3
6 .Os
7 .\"
8 .Sh NAME
9 .Nm atexit
10 .Nd registration of functions to be invoked before process termination
11 .\"
12 .Sh SYNOPSIS
13 .In stdlib.h
14 .Fn "int atexit" "void (*handler)(void)"
15 .Fn "int at_quick_exit" "void (*handler)(void)" 
16 (C11, C++11)
17 .\"
18 .Sh DESCRIPTION
19 These functions register a function to be called when the corresponding process
20 exit function is invoked. For
21 .Fn atexit 
22 the function will be invoked when the process is terminated by calling
23 .Fn exit ;
24 for
25 .Fn at_quick_exit
26 the function will be invoked when the process is terminated by calling
27 .Fn quick_exit .
28 .\"
29 .Pp
30 These functions are used in order to permit a program to perform actions before
31 a process is terminated; for example, releasing an interprocess semaphore. 
32 Special care should be taken when writing 
33 .Fn at_quick_exit
34 handlers; the purpose of 
35 .Fn quick_exit
36 is to support the abandonning of a process when normal process termination might
37 not be possible; at_quick_exit handlers should therefore be used sparingly and
38 only when their use is essential.
39 .\"
40 .Pp
41 The standard guarantees that 
42 .Fn atexit
43 and
44 .Fn at_quick_exit
45 may each be called at least 32 times successfully.
46 .\"
47 .Pp
48 .Fn atexit 
49 and
50 .Fn at_quick_exit
51 handlers are called in reverse order of the order they were registered in. For
52 precise details of their ordering, see
53 .Xr exit 3 .
54 .\"
55 .Pp
56 The result of exiting from a handler registered with
57 .Fn atexit
58 or
59 .Fn at_quick_exit
60 by use of 
61 .Fn longjmp
62 is undefined. If any function or destructor invoked by
63 .Fn exit
64 or
65 .Fn quick_exit
66 should throw, 
67 .Fn std::terminate
68 is invoked.
69 .\"
70 .Pp
71 Undefined behaviour results if an 
72 .Fn atexit
73 or
74 .Fn at_quick_exit
75 handler calls
76 .Fn exit
77 or
78 .Fn quick_exit . 
79 .\"
80 .Sh RETURN VALUES
81 Returns 0 to indicate success; nonzero returns indicate failure.
82 .\"
83 .Sh ERRORS
84 No errors are defined
85 .\"
86 .Sh SEE ALSO
87 .Xr abort 3
88 .Xr exit 3
89 .Xr quick_exit 3
90 .Xr _Exit 3
91 .\"
92 .Sh STANDARDS
93 .Fn atexit
94 is first defined in
95 .St -isoC-90 ;
96 .Fn at_quick_exit
97 was introduced in
98 .St -isoC-2011 
99 and
100 ISO/IEC 14882:2011 "C++ 2011" .