OSDN Git Service

(split) LDP_man-pages: release ioctl.2 [JM:00378]
[linuxjm/LDP_man-pages.git] / draft / man3 / atexit.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\"     Linux libc source code
25 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\"     386BSD man pages
27 .\" Modified 1993-03-29, David Metcalfe
28 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
29 .\" Modified 2003-10-25, Walter Harms
30 .\"
31 .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA
32 .\"         all rights reserved.
33 .\" Translated 2006-07-14, Kentaro OGAWA <k_ogawa@oyna.cc.muroran-it.ac.jp>
34 .\" Updated & Modified 2004-05-23, Yuichi SATO <ysato444@yahoo.co.jp>
35 .\" Updated 2008-12-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.15
36 .\"
37 .TH ATEXIT 3  2008-12-05 "Linux" "Linux Programmer's Manual"
38 .\"O .SH NAME
39 .SH Ì¾Á°
40 .\"O atexit \- register a function to be called at normal process termination
41 atexit \- ¥×¥í¥»¥¹¤¬Àµ¾ï½ªÎ»¤·¤¿»þ¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë´Ø¿ô¤òÅÐÏ¿¤¹¤ë
42 .\"O .SH SYNOPSIS
43 .SH ½ñ¼°
44 .nf
45 .B #include <stdlib.h>
46 .sp
47 .BI "int atexit(void (*" function )(void));
48 .fi
49 .\"O .SH DESCRIPTION
50 .SH ÀâÌÀ
51 .\"O The
52 .\"O .BR atexit ()
53 .\"O function registers the given \fIfunction\fP to be
54 .\"O called at normal process termination, either via
55 .\"O .BR exit (3)
56 .\"O or via return from the program's \fImain\fP().
57 .BR atexit ()
58 ´Ø¿ô¤Ï¡¢Í¿¤¨¤é¤ì¤¿ \fIfunction\fP ¤ò¡¢
59 .BR exit (3)
60 ¤ä¥×¥í¥°¥é¥à¤Î \fImain\fP()
61 ´Ø¿ô¤«¤é¤ÎÊÖ¤ê¤òÄ̤¸¤Æ¡¢¥×¥í¥»¥¹¤¬Àµ¾ï½ªÎ»¤·¤¿»þ¤Ë¸Æ¤Ó½Ð¤µ¤ì¤ë
62 ´Ø¿ô¤È¤·¤ÆÅÐÏ¿¤¹¤ë¡£
63 .\"O Functions so registered are called in
64 .\"O the reverse order of their registration; no arguments are passed.
65 ¤³¤³¤ÇÄêµÁ¤µ¤ì¤¿´Ø¿ô¤Ï¡¢ÅÐÏ¿¤·¤¿½çÈ֤ȤϵդνçÈ֤ǸƤӽФµ¤ì¤ë¡£
66 ÅÐÏ¿¤·¤¿´Ø¿ô¤Ë°ú¤­¿ô¤ÏÅϤµ¤ì¤Ê¤¤¡£
67
68 .\"O The same function may be registered multiple times:
69 .\"O it is called once for each registration.
70 Ʊ¤¸´Ø¿ô¤òÊ£¿ô²óÅÐÏ¿¤·¤Æ¤â¤è¤¤¡£
71 ÅÐÏ¿¤µ¤ì¤¿´Ø¿ô¤ÏÅÐÏ¿ 1 ²ó¤Ë¤Ä¤­ 1 ²ó¸Æ¤Ó½Ð¤µ¤ì¤ë¡£
72 .LP
73 .\"O POSIX.1-2001 requires that an implementation allow at least
74 .\"O .B ATEXIT_MAX
75 .\"O (32) such functions to be registered.
76 .\"O The actual limit supported by an implementation can be obtained using
77 .\"O .BR sysconf (3).
78 POSIX.1-2001 ¤Ç¤Ï¡¢¤³¤Î¤è¤¦¤Ê´Ø¿ô¤ò¾¯¤Ê¤¯¤È¤â
79 .B ATEXIT_MAX
80 ¸Ä (32¸Ä) ÅÐÏ¿¤Ç¤­¤ë¤³¤È¤òÍ׵ᤷ¤Æ¤¤¤ë¡£
81 ¤½¤Î¼ÂÁõ¤Ç¥µ¥Ý¡¼¥È¤µ¤ì¤Æ¤¤¤ë¼ÂºÝ¤Î¾å¸Â¤Ï
82 .BR sysconf (3)
83 ¤ò»È¤Ã¤Æ¼èÆÀ¤Ç¤­¤ë¡£
84 .LP
85 .\"O When a child process is created via
86 .\"O .BR fork (2),
87 .\"O it inherits copies of its parent's registrations.
88 .BR fork (2)
89 ¤ÇºîÀ®¤µ¤ì¤¿¾ì¹ç¡¢»Ò¥×¥í¥»¥¹¤Ï¿Æ¥×¥í¥»¥¹¤ÎÅÐÏ¿¤Î¥³¥Ô¡¼¤ò·Ñ¾µ¤¹¤ë¡£
90 .\"O Upon a successful call to one of the
91 .\"O .BR exec (3)
92 .\"O functions,
93 .\"O all registrations are removed.
94 .BR exec (3)
95 ¥Õ¥¡¥ß¥ê¡¼¤Î´Ø¿ô¤Î¤¤¤º¤ì¤«¤Î¸Æ¤Ó½Ð¤·¤ËÀ®¸ù¤¹¤ë¤È¡¢
96 Á´¤Æ¤ÎÅÐÏ¿¤¬ºï½ü¤µ¤ì¤ë¡£
97 .\"O .SH "RETURN VALUE"
98 .SH ÊÖ¤êÃÍ
99 .\"O The
100 .\"O .BR atexit ()
101 .\"O function returns the value 0 if successful; otherwise
102 .\"O it returns a nonzero value.
103 .BR atexit ()
104 ´Ø¿ô¤Ï¡¢´Ø¿ôÅÐÏ¿¤¬À®¸ù¤·¤¿»þ¤Ë¤Ï 0 ¤òÊÖ¤¹¡£
105 ¤½¤Î¾¤Î¾ì¹ç¤Ë¤Ï 0 °Ê³°¤ÎÃͤòÊÖ¤¹¡£
106 .\"O .SH "CONFORMING TO"
107 .SH ½àµò
108 SVr4, 4.3BSD, C89, C99, POSIX.1-2001.
109 .\"O .SH NOTES
110 .SH Ãí°Õ
111 .\"O Functions registered using
112 .\"O .BR atexit ()
113 .\"O (and
114 .\"O .BR on_exit (3))
115 .\"O are not called if a process terminates abnormally because
116 .\"O of the delivery of a signal.
117 .BR atexit ()
118 (¤È
119 .BR on_exit (3))
120 ¤ò»È¤Ã¤ÆÅÐÏ¿¤µ¤ì¤¿´Ø¿ô¤Ï¡¢
121 ¥·¥°¥Ê¥ë¤ÎÇÛÁ÷¤Ë¤è¤ê¥×¥í¥»¥¹¤¬°Û¾ï½ªÎ»¤·¤¿¾ì¹ç¤Ë¤Ï¸Æ¤Ó½Ð¤µ¤ì¤Ê¤¤¡£
122
123 .\"O If one of the functions registered functions calls
124 .\"O .BR _exit (2),
125 .\"O then any remaining functions are not invoked,
126 .\"O and the other process termination steps performed by
127 .\"O .BR exit (3)
128 .\"O are not performed.
129 ÅÐÏ¿¤µ¤ì¤¿´Ø¿ô¤Î°ì¤Ä¤¬
130 .BR _exit (2)
131 ¤ò¸Æ¤Ó½Ð¤·¤¿¾ì¹ç¡¢»Ä¤ê¤Î´Ø¿ô¤Ï¤É¤ì¤âµ¯Æ°¤µ¤ì¤º¡¢
132 .BR exit (3)
133 ¤Ë¤è¤ê¼Â¹Ô¤µ¤ì¤ë¾¤Î¥×¥í¥»¥¹½ªÎ»¥¹¥Æ¥Ã¥×¤Ï¼Â¹Ô¤µ¤ì¤Ê¤¤¡£
134
135 .\"O POSIX.1-2001 says that the result of calling
136 .\"O .BR exit (3)
137 .\"O more than once (i.e., calling
138 .\"O .BR exit (3)
139 .\"O within a function registered using
140 .\"O .BR atexit ())
141 .\"O is undefined.
142 POSIX.1-2001 ¤Ç¤Ï¡¢
143 .BR atexit ()
144 ¤ò»È¤Ã¤ÆÅÐÏ¿¤µ¤ì¤¿°ì¤Ä¤Î´Ø¿ôÆâ¤Ç¡¢Ê£¿ô²ó
145 .BR exit (3)
146 ¤ò¸Æ¤Ó½Ð¤·¤¿ºÝ¤Î·ë²Ì¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£
147 .\"O On some systems (but not Linux), this can result in an infinite recursion;
148 .\" This can happen on OpenBSD 4.2 for example, and is documented
149 .\" as occurring on FreeBSD as well.
150 .\" Glibc does "the Right Thing" -- invocation of the remaining
151 .\" exit handlers carries on as normal.
152 .\"O portable programs should not invoke
153 .\"O .BR exit (3)
154 .\"O inside a function registered using
155 .\"O .BR atexit ().
156 (Linux ¤Ç¤Ï¤Ê¤¤¤¬) ¤¤¤¯¤Ä¤«¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¡¢¤³¤Î¾ì¹ç¡¢
157 ·«¤êÊÖ¤·¤¬Ìµ¸Â¤Ëµ¯¤³¤ë¤³¤È¤Ë¤Ê¤ë¡£
158 °Ü¿¢À­¤¬É¬Í×¤Ê¥×¥í¥°¥é¥à¤Ç¤Ï¡¢
159 .BR atexit ()
160 ¤ÇÅÐÏ¿¤µ¤ì¤¿´Ø¿ôÆâ¤Ç
161 .BR exit (3)
162 ¤òµ¯Æ°¤¹¤Ù¤­¤Ç¤Ï¤Ê¤¤¡£
163
164 .\"O The
165 .\"O .BR atexit ()
166 .\"O and
167 .\"O .BR on_exit (3)
168 .\"O functions register functions on the same list:
169 .\"O at normal process termination,
170 .\"O the registered functions are invoked in reverse order
171 .\"O of their registration by these two functions.
172 .BR atexit ()
173 ¤È
174 .BR on_exit (3)
175 ¤Ï¡¢Æ±¤¸¥ê¥¹¥È¤ËÂФ·¤Æ´Ø¿ô¤òÅÐÏ¿¤¹¤ë¡£
176 ¥×¥í¥»¥¹¤¬Àµ¾ï¤Ë½ªÎ»¤·¤¿ºÝ¤Ë¤Ï¡¢
177 ¤³¤ì¤é¤ÎÆó¤Ä¤Î´Ø¿ô¤ÇÅÐÏ¿¤µ¤ì¤¿½ç½ø¤ÎµÕ½ç¤Ç¡¢
178 ÅÐÏ¿¤µ¤ì¤¿´Ø¿ô¤¬µ¯Æ°¤µ¤ì¤ë¡£
179
180 .\"O POSIX.1-2001 says that the result is undefined if
181 .\"O .BR longjmp (3)
182 .\"O is used to terminate execution of one of the functions registered
183 .\"O .BR atexit ().
184 POSIX.1-2001 ¤Ç¤Ï¡¢
185 .BR atexit ()
186 ¤ÇÅÐÏ¿¤µ¤ì¤¿´Ø¿ô¤Î¼Â¹Ô¤ò½ªÎ»¤¹¤ë¤¿¤á¤Ë
187 .BR longjmp (3)
188 ¤¬»ÈÍѤµ¤ì¤¿¾ì¹ç¤Î·ë²Ì¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£
189 .\" In glibc, things seem to be handled okay
190 .\"O .SS "Linux Notes"
191 .SS Linux ¤Ç¤ÎÃí°Õ
192 .\"O Since glibc 2.2.3,
193 .\"O .BR atexit ()
194 .\"O (and
195 .\"O .BR on_exit (3))
196 .\"O can be used to within a shared library to establish functions
197 .\"O that are called when the shared library is unloaded.
198 glibc 2.2.3 °Ê¹ß¤Ç¤Ï¡¢¶¦Í­¥é¥¤¥Ö¥é¥ê¤¬¥¢¥ó¥í¡¼¥É¤µ¤ì¤ë¤È¤­¤Ë¸Æ¤Ð¤ì¤ë
199 ´Ø¿ô¤òÅÐÏ¿¤¹¤ë¤¿¤á¤Ë¡¢¶¦Í­¥é¥¤¥Ö¥é¥ê¤ÎÃæ¤Ç
200 .BR atexit ()
201 (¤È
202 .BR on_exit (3))
203 ¤ò»ÈÍѤ¹¤ë¤³¤È¤¬¤Ç¤­¤ë¡£
204 .PP
205 .\"O .SH EXAMPLE
206 .SH Îã
207 .nf
208 #include <stdio.h>
209 #include <stdlib.h>
210 #include <unistd.h>
211
212 void
213 bye(void)
214 {
215     printf("That was all, folks\en");
216 }
217
218 int
219 main(void)
220 {
221     long a;
222     int i;
223
224     a = sysconf(_SC_ATEXIT_MAX);
225     printf("ATEXIT_MAX = %ld\en", a);
226
227     i = atexit(bye);
228     if (i != 0) {
229         fprintf(stderr, "cannot set exit function\en");
230         exit(EXIT_FAILURE);
231     }
232
233     exit(EXIT_SUCCESS);
234 }
235 .fi
236 .\"O .SH "SEE ALSO"
237 .SH ´ØÏ¢¹àÌÜ
238 .BR _exit (2),
239 .BR exit (3),
240 .BR on_exit (3)