Unleashed v1.4
[unleashed.git] / share / man / man3c / atexit.3c
blob4c44887a168cb55bcbe96e927f41535da19e1e96
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright 1989 AT&T
44 .\" Copyright (c) 1997, The Open Group. All Rights Reserved.
45 .\" Portions Copyright (c) 2001, Sun Microsystems, Inc.  All Rights Reserved
46 .\"
47 .TH ATEXIT 3C "May 25, 2001"
48 .SH NAME
49 atexit \- register a function to run at process termination or object unloading
50 .SH SYNOPSIS
51 .LP
52 .nf
53 #include <stdlib.h>
55 \fBint\fR \fBatexit\fR(\fBvoid (*\fR\fIfunc\fR)(void));
56 .fi
58 .SH DESCRIPTION
59 .sp
60 .LP
61 The \fBatexit()\fR function registers the function pointed to by \fIfunc\fR to
62 be called without arguments on normal termination of the program or when the
63 object defining the function is unloaded.
64 .sp
65 .LP
66 Normal termination occurs by either a call to the \fBexit\fR(3C) function or a
67 return from \fBmain()\fR. Object unloading occurs when a call to
68 \fBdlclose\fR(3C) results in the object becoming unreferenced.
69 .sp
70 .LP
71 The number of functions that may be registered with \fBatexit()\fR is limited
72 only by available memory (refer to the \fB_SC_ATEXIT_MAX\fR argument of
73 \fBsysconf\fR(3C)).
74 .sp
75 .LP
76 After a successful call to any of the \fBexec\fR(2) functions, any functions
77 previously registered by \fBatexit()\fR are no longer registered.
78 .sp
79 .LP
80 On process exit, functions are called in the reverse order of their
81 registration. On object unloading, any functions belonging to an unloadable
82 object are called in the reverse order of their registration.
83 .SH RETURN VALUES
84 .sp
85 .LP
86 Upon successful completion, the \fBatexit()\fR function returns 0. Otherwise,
87 it returns a non-zero value.
88 .SH ERRORS
89 .sp
90 .LP
91 The \fBatexit()\fR function may fail if:
92 .sp
93 .ne 2
94 .na
95 \fB\fBENOMEM\fR\fR
96 .ad
97 .RS 10n
98 Insufficient storage space is available.
99 .RE
101 .SH USAGE
104 The functions registered by a call to \fBatexit()\fR must return to ensure that
105 all registered functions are called.
108 There is no way for an application to tell how many functions have already been
109 registered with \fBatexit()\fR.
110 .SH ATTRIBUTES
113 See \fBattributes\fR(5) for descriptions of the following attributes:
118 box;
119 c | c
120 l | l .
121 ATTRIBUTE TYPE  ATTRIBUTE VALUE
123 Interface Stability     Standard
125 MT-Level        Safe
128 .SH SEE ALSO
131 \fBexec\fR(2), \fBdlclose\fR(3C), \fBexit\fR(3C), \fBsysconf\fR(3C),
132 \fBattributes\fR(5)