.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified 1993-03-29, David Metcalfe .\" Modified 1993-07-24, Rik Faith (faith@cs.unc.edu) .\" Modified 2003-10-25, Walter Harms .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1996 Kentaro OGAWA .\" all rights reserved. .\" Translated 2006-07-14, Kentaro OGAWA .\" Updated & Modified 2004-05-23, Yuichi SATO .\" Updated 2008-12-26, Akihiro MOTOKI , LDP v3.15 .\" .TH ATEXIT 3 2008\-12\-05 Linux "Linux Programmer's Manual" .SH 名前 atexit \- プロセスが正常終了した時に呼び出される関数を登録する .SH 書式 .nf \fB#include \fP .sp \fBint atexit(void (*\fP\fIfunction\fP\fB)(void));\fP .fi .SH 説明 \fBatexit\fP() 関数は、与えられた \fIfunction\fP を、 \fBexit\fP(3) やプログラムの \fImain\fP() 関数からの返りを通じて、プロセスが正常終了した時に呼び出される 関数として登録する。 ここで定義された関数は、登録した順番とは逆の順番で呼び出される。 登録した関数に引き数は渡されない。 同じ関数を複数回登録してもよい。 登録された関数は登録 1 回につき 1 回呼び出される。 .LP POSIX.1\-2001 では、このような関数を少なくとも \fBATEXIT_MAX\fP 個 (32個) 登録できることを要求している。 その実装でサポートされている実際の上限は \fBsysconf\fP(3) を使って取得できる。 .LP \fBfork\fP(2) で作成された場合、子プロセスは親プロセスの登録のコピーを継承する。 \fBexec\fP(3) ファミリーの関数の場合、呼び出しに成功すると、 全ての登録が削除される。 .SH 返り値 \fBatexit\fP() 関数は、関数登録が成功した時には 0 を返す。 その他の場合には 0 以外の値を返す。 .SH 準拠 SVr4, 4.3BSD, C89, C99, POSIX.1\-2001. .SH 注意 \fBatexit\fP() (と \fBon_exit\fP(3)) を使って登録された関数は、 シグナルの配送によりプロセスが異常終了した場合には呼び出されない。 登録された関数の一つが \fB_exit\fP(2) を呼び出した場合、残りの関数はどれも起動されず、 \fBexit\fP(3) により実行される他のプロセス終了ステップは実行されない。 .\" This can happen on OpenBSD 4.2 for example, and is documented .\" as occurring on FreeBSD as well. .\" Glibc does "the Right Thing" -- invocation of the remaining .\" exit handlers carries on as normal. POSIX.1\-2001 では、 \fBatexit\fP() を使って登録された一つの関数内で、複数回 \fBexit\fP(3) を呼び出した際の結果は未定義である。 (Linux ではないが) いくつかのシステムでは、この場合、 繰り返しが無限に起こることになる。 移植性が必要なプログラムでは、 \fBatexit\fP() で登録された関数内で \fBexit\fP(3) を起動すべきではない。 \fBatexit\fP() と \fBon_exit\fP(3) は、同じリストに対して関数を登録する。 プロセスが正常に終了した際には、 これらの二つの関数で登録された順序の逆順で、 登録された関数が起動される。 .\" In glibc, things seem to be handled okay POSIX.1\-2001 では、 \fBatexit\fP() で登録された関数の実行を終了するために \fBlongjmp\fP(3) が使用された場合の結果は未定義である。 .SS "Linux での注意" glibc 2.2.3 以降では、共有ライブラリがアンロードされるときに呼ばれる 関数を登録するために、共有ライブラリの中で \fBatexit\fP() (と \fBon_exit\fP(3)) を使用することができる。 .SH 例 .nf #include #include #include void bye(void) { printf("That was all, folks\en"); } int main(void) { long a; int i; a = sysconf(_SC_ATEXIT_MAX); printf("ATEXIT_MAX = %ld\en", a); i = atexit(bye); if (i != 0) { fprintf(stderr, "cannot set exit function\en"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fB_exit\fP(2), \fBexit\fP(3), \fBon_exit\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。