OSDN Git Service

(split) LDP: Update the version to 3.53 in PO files
[linuxjm/LDP_man-pages.git] / release / man3 / atexit.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" References consulted:
26 .\"     Linux libc source code
27 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
28 .\"     386BSD man pages
29 .\" Modified 1993-03-29, David Metcalfe
30 .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu)
31 .\" Modified 2003-10-25, Walter Harms
32 .\"
33 .\"*******************************************************************
34 .\"
35 .\" This file was generated with po4a. Translate the source file.
36 .\"
37 .\"*******************************************************************
38 .TH ATEXIT 3 2008\-12\-05 Linux "Linux Programmer's Manual"
39 .SH 名前
40 atexit \- プロセスが正常終了した時に呼び出される関数を登録する
41 .SH 書式
42 .nf
43 \fB#include <stdlib.h>\fP
44 .sp
45 \fBint atexit(void (*\fP\fIfunction\fP\fB)(void));\fP
46 .fi
47 .SH 説明
48 \fBatexit\fP()  関数は、与えられた \fIfunction\fP を、 \fBexit\fP(3)  やプログラムの \fImain\fP()
49 関数からの返りを通じて、プロセスが正常終了した時に呼び出される 関数として登録する。 ここで定義された関数は、登録した順番とは逆の順番で呼び出される。
50 登録した関数に引き数は渡されない。
51
52 同じ関数を複数回登録してもよい。 登録された関数は登録 1 回につき 1 回呼び出される。
53 .LP
54 POSIX.1\-2001 では、このような関数を少なくとも \fBATEXIT_MAX\fP 個 (32個) 登録できることを要求している。
55 その実装でサポートされている実際の上限は \fBsysconf\fP(3)  を使って取得できる。
56 .LP
57 \fBfork\fP(2) で作成された場合、子プロセスは親プロセスの登録のコピーを継承する。
58 \fBexec\fP(3) ファミリーの関数の場合、呼び出しに成功すると、 全ての登録が削除される。
59 .SH 返り値
60 \fBatexit\fP()  関数は、関数登録が成功した時には 0 を返す。 その他の場合には 0 以外の値を返す。
61 .SH 準拠
62 SVr4, 4.3BSD, C89, C99, POSIX.1\-2001.
63 .SH 注意
64 \fBatexit\fP()  (と \fBon_exit\fP(3))  を使って登録された関数は、
65 シグナルの配送によりプロセスが異常終了した場合には呼び出されない。
66
67 登録された関数の一つが \fB_exit\fP(2)  を呼び出した場合、残りの関数はどれも起動されず、 \fBexit\fP(3)
68 により実行される他のプロセス終了ステップは実行されない。
69
70 .\" This can happen on OpenBSD 4.2 for example, and is documented
71 .\" as occurring on FreeBSD as well.
72 .\" Glibc does "the Right Thing" -- invocation of the remaining
73 .\" exit handlers carries on as normal.
74 POSIX.1\-2001 では、 \fBatexit\fP()  を使って登録された一つの関数内で、複数回 \fBexit\fP(3)
75 を呼び出した際の結果は未定義である。 (Linux ではないが) いくつかのシステムでは、この場合、 繰り返しが無限に起こることになる。
76 移植性が必要なプログラムでは、 \fBatexit\fP()  で登録された関数内で \fBexit\fP(3)  を起動すべきではない。
77
78 \fBatexit\fP()  と \fBon_exit\fP(3)  は、同じリストに対して関数を登録する。 プロセスが正常に終了した際には、
79 これらの二つの関数で登録された順序の逆順で、 登録された関数が起動される。
80
81 .\" In glibc, things seem to be handled okay
82 POSIX.1\-2001 では、 \fBatexit\fP()  で登録された関数の実行を終了するために \fBlongjmp\fP(3)
83 が使用された場合の結果は未定義である。
84 .SS "Linux での注意"
85 glibc 2.2.3 以降では、共有ライブラリがアンロードされるときに呼ばれる 関数を登録するために、共有ライブラリの中で \fBatexit\fP()
86 (と \fBon_exit\fP(3))  を使用することができる。
87 .SH 例
88 .nf
89 #include <stdio.h>
90 #include <stdlib.h>
91 #include <unistd.h>
92
93 void
94 bye(void)
95 {
96     printf("That was all, folks\en");
97 }
98
99 int
100 main(void)
101 {
102     long a;
103     int i;
104
105     a = sysconf(_SC_ATEXIT_MAX);
106     printf("ATEXIT_MAX = %ld\en", a);
107
108     i = atexit(bye);
109     if (i != 0) {
110         fprintf(stderr, "cannot set exit function\en");
111         exit(EXIT_FAILURE);
112     }
113
114     exit(EXIT_SUCCESS);
115 }
116 .fi
117 .SH 関連項目
118 \fB_exit\fP(2), \fBexit\fP(3), \fBon_exit\fP(3)
119 .SH この文書について
120 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.53 の一部
121 である。プロジェクトの説明とバグ報告に関する情報は
122 http://www.kernel.org/doc/man\-pages/ に書かれている。