on_exit

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

on_exit - プロセスが正常に終了した際に呼ばれる関数を登録する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <stdlib.h>

int on_exit(typeof(void (int, void *)) *function, void *arg);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

on_exit():

    Since glibc 2.19:
        _DEFAULT_SOURCE
    glibc 2.19 and earlier:
        _BSD_SOURCE || _SVID_SOURCE
 

説明

on_exit() 関数は、指定された関数 function を、プロセスが 正常に終了した際に呼ばれる関数として登録する。正常な終了とは、 exit(3) またはプログラムの main() 関数の中の return 命令による終了である。 関数 function には、直近の exit(3) の呼び出しで渡された status 引数と on_exit() の arg 引数が渡される。

同じ関数を複数回登録してもよい。 登録された関数は登録 1 回につき 1 回呼び出される。

fork(2) で作成された場合、子プロセスは親プロセスの登録のコピーを継承する。 exec(3) ファミリーの関数の場合、呼び出しに成功すると、 全ての登録が削除される。  

返り値

The on_exit() function returns the value 0 if successful; otherwise, it returns a nonzero value.  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
on_exit() Thread safetyMT-Safe
 

標準規格

なし。  

歴史

SunOS 4, glibc. Removed in Solaris (SunOS 5). Use the standard atexit(3) instead.  

警告

By the time function is executed, stack (auto) variables may already have gone out of scope. Therefore, arg should not be a pointer to a stack variable; it may however be a pointer to a heap variable or a global variable.  

関連項目

_exit(2), atexit(3), exit(3)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
警告
関連項目

This document was created by man2html, using the manual pages.