OSDN Git Service

(split) LDP: Release pages for LDP v3.39.
[linuxjm/LDP_man-pages.git] / release / 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 .\"*******************************************************************
32 .\"
33 .\" This file was generated with po4a. Translate the source file.
34 .\"
35 .\"*******************************************************************
36 .TH ATEXIT 3 2008\-12\-05 Linux "Linux Programmer's Manual"
37 .SH 名前
38 atexit \- プロセスが正常終了した時に呼び出される関数を登録する
39 .SH 書式
40 .nf
41 \fB#include <stdlib.h>\fP
42 .sp
43 \fBint atexit(void (*\fP\fIfunction\fP\fB)(void));\fP
44 .fi
45 .SH 説明
46 \fBatexit\fP()  関数は、与えられた \fIfunction\fP を、 \fBexit\fP(3)  やプログラムの \fImain\fP()
47 関数からの返りを通じて、プロセスが正常終了した時に呼び出される 関数として登録する。 ここで定義された関数は、登録した順番とは逆の順番で呼び出される。
48 登録した関数に引き数は渡されない。
49
50 同じ関数を複数回登録してもよい。 登録された関数は登録 1 回につき 1 回呼び出される。
51 .LP
52 POSIX.1\-2001 では、このような関数を少なくとも \fBATEXIT_MAX\fP 個 (32個) 登録できることを要求している。
53 その実装でサポートされている実際の上限は \fBsysconf\fP(3)  を使って取得できる。
54 .LP
55 \fBfork\fP(2) で作成された場合、子プロセスは親プロセスの登録のコピーを継承する。
56 \fBexec\fP(3) ファミリーの関数の場合、呼び出しに成功すると、 全ての登録が削除される。
57 .SH 返り値
58 \fBatexit\fP()  関数は、関数登録が成功した時には 0 を返す。 その他の場合には 0 以外の値を返す。
59 .SH 準拠
60 SVr4, 4.3BSD, C89, C99, POSIX.1\-2001.
61 .SH 注意
62 \fBatexit\fP()  (と \fBon_exit\fP(3))  を使って登録された関数は、
63 シグナルの配送によりプロセスが異常終了した場合には呼び出されない。
64
65 登録された関数の一つが \fB_exit\fP(2)  を呼び出した場合、残りの関数はどれも起動されず、 \fBexit\fP(3)
66 により実行される他のプロセス終了ステップは実行されない。
67
68 .\" This can happen on OpenBSD 4.2 for example, and is documented
69 .\" as occurring on FreeBSD as well.
70 .\" Glibc does "the Right Thing" -- invocation of the remaining
71 .\" exit handlers carries on as normal.
72 POSIX.1\-2001 では、 \fBatexit\fP()  を使って登録された一つの関数内で、複数回 \fBexit\fP(3)
73 を呼び出した際の結果は未定義である。 (Linux ではないが) いくつかのシステムでは、この場合、 繰り返しが無限に起こることになる。
74 移植性が必要なプログラムでは、 \fBatexit\fP()  で登録された関数内で \fBexit\fP(3)  を起動すべきではない。
75
76 \fBatexit\fP()  と \fBon_exit\fP(3)  は、同じリストに対して関数を登録する。 プロセスが正常に終了した際には、
77 これらの二つの関数で登録された順序の逆順で、 登録された関数が起動される。
78
79 .\" In glibc, things seem to be handled okay
80 POSIX.1\-2001 では、 \fBatexit\fP()  で登録された関数の実行を終了するために \fBlongjmp\fP(3)
81 が使用された場合の結果は未定義である。
82 .SS "Linux での注意"
83 glibc 2.2.3 以降では、共有ライブラリがアンロードされるときに呼ばれる 関数を登録するために、共有ライブラリの中で \fBatexit\fP()
84 (と \fBon_exit\fP(3))  を使用することができる。
85 .SH 例
86 .nf
87 #include <stdio.h>
88 #include <stdlib.h>
89 #include <unistd.h>
90
91 void
92 bye(void)
93 {
94     printf("That was all, folks\en");
95 }
96
97 int
98 main(void)
99 {
100     long a;
101     int i;
102
103     a = sysconf(_SC_ATEXIT_MAX);
104     printf("ATEXIT_MAX = %ld\en", a);
105
106     i = atexit(bye);
107     if (i != 0) {
108         fprintf(stderr, "cannot set exit function\en");
109         exit(EXIT_FAILURE);
110     }
111
112     exit(EXIT_SUCCESS);
113 }
114 .fi
115 .SH 関連項目
116 \fB_exit\fP(2), \fBexit\fP(3), \fBon_exit\fP(3)