.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" 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. .\" .\" 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 .\" .\" 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" .\"O .SH NAME .SH 名前 .\"O atexit \- register a function to be called at normal process termination atexit \- プロセスが正常終了した時に呼び出される関数を登録する .\"O .SH SYNOPSIS .SH 書式 .nf .B #include .sp .BI "int atexit(void (*" function )(void)); .fi .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR atexit () .\"O function registers the given \fIfunction\fP to be .\"O called at normal process termination, either via .\"O .BR exit (3) .\"O or via return from the program's \fImain\fP(). .BR atexit () 関数は、与えられた \fIfunction\fP を、 .BR exit (3) やプログラムの \fImain\fP() 関数からの返りを通じて、プロセスが正常終了した時に呼び出される 関数として登録する。 .\"O Functions so registered are called in .\"O the reverse order of their registration; no arguments are passed. ここで定義された関数は、登録した順番とは逆の順番で呼び出される。 登録した関数に引き数は渡されない。 .\"O The same function may be registered multiple times: .\"O it is called once for each registration. 同じ関数を複数回登録してもよい。 登録された関数は登録 1 回につき 1 回呼び出される。 .LP .\"O POSIX.1-2001 requires that an implementation allow at least .\"O .B ATEXIT_MAX .\"O (32) such functions to be registered. .\"O The actual limit supported by an implementation can be obtained using .\"O .BR sysconf (3). POSIX.1-2001 では、このような関数を少なくとも .B ATEXIT_MAX 個 (32個) 登録できることを要求している。 その実装でサポートされている実際の上限は .BR sysconf (3) を使って取得できる。 .LP .\"O When a child process is created via .\"O .BR fork (2), .\"O it inherits copies of its parent's registrations. .BR fork (2) で作成された場合、子プロセスは親プロセスの登録のコピーを継承する。 .\"O Upon a successful call to one of the .\"O .BR exec (3) .\"O functions, .\"O all registrations are removed. .BR exec (3) ファミリーの関数のいずれかの呼び出しに成功すると、 全ての登録が削除される。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O The .\"O .BR atexit () .\"O function returns the value 0 if successful; otherwise .\"O it returns a nonzero value. .BR atexit () 関数は、関数登録が成功した時には 0 を返す。 その他の場合には 0 以外の値を返す。 .\"O .SH "CONFORMING TO" .SH 準拠 SVr4, 4.3BSD, C89, C99, POSIX.1-2001. .\"O .SH NOTES .SH 注意 .\"O Functions registered using .\"O .BR atexit () .\"O (and .\"O .BR on_exit (3)) .\"O are not called if a process terminates abnormally because .\"O of the delivery of a signal. .BR atexit () (と .BR on_exit (3)) を使って登録された関数は、 シグナルの配送によりプロセスが異常終了した場合には呼び出されない。 .\"O If one of the functions registered functions calls .\"O .BR _exit (2), .\"O then any remaining functions are not invoked, .\"O and the other process termination steps performed by .\"O .BR exit (3) .\"O are not performed. 登録された関数の一つが .BR _exit (2) を呼び出した場合、残りの関数はどれも起動されず、 .BR exit (3) により実行される他のプロセス終了ステップは実行されない。 .\"O POSIX.1-2001 says that the result of calling .\"O .BR exit (3) .\"O more than once (i.e., calling .\"O .BR exit (3) .\"O within a function registered using .\"O .BR atexit ()) .\"O is undefined. POSIX.1-2001 では、 .BR atexit () を使って登録された一つの関数内で、複数回 .BR exit (3) を呼び出した際の結果は未定義である。 .\"O On some systems (but not Linux), this can result in an infinite recursion; .\" 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. .\"O portable programs should not invoke .\"O .BR exit (3) .\"O inside a function registered using .\"O .BR atexit (). (Linux ではないが) いくつかのシステムでは、この場合、 繰り返しが無限に起こることになる。 移植性が必要なプログラムでは、 .BR atexit () で登録された関数内で .BR exit (3) を起動すべきではない。 .\"O The .\"O .BR atexit () .\"O and .\"O .BR on_exit (3) .\"O functions register functions on the same list: .\"O at normal process termination, .\"O the registered functions are invoked in reverse order .\"O of their registration by these two functions. .BR atexit () と .BR on_exit (3) は、同じリストに対して関数を登録する。 プロセスが正常に終了した際には、 これらの二つの関数で登録された順序の逆順で、 登録された関数が起動される。 .\"O POSIX.1-2001 says that the result is undefined if .\"O .BR longjmp (3) .\"O is used to terminate execution of one of the functions registered .\"O .BR atexit (). POSIX.1-2001 では、 .BR atexit () で登録された関数の実行を終了するために .BR longjmp (3) が使用された場合の結果は未定義である。 .\" In glibc, things seem to be handled okay .\"O .SS "Linux Notes" .SS Linux での注意 .\"O Since glibc 2.2.3, .\"O .BR atexit () .\"O (and .\"O .BR on_exit (3)) .\"O can be used to within a shared library to establish functions .\"O that are called when the shared library is unloaded. glibc 2.2.3 以降では、共有ライブラリがアンロードされるときに呼ばれる 関数を登録するために、共有ライブラリの中で .BR atexit () (と .BR on_exit (3)) を使用することができる。 .PP .\"O .SH EXAMPLE .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 .\"O .SH "SEE ALSO" .SH 関連項目 .BR _exit (2), .BR exit (3), .BR on_exit (3)