Man page - exit(3)

Packages contains this manual

Available languages:

en fr it pl ja ru ro zh_TW zh_CN de

Manual

EXIT

名 前
書 式
説 明
返 り 値
属 性
準 拠
注 意
Signals sent to other processes
関 連 項 目
こ の 文 書 に つ い て

名 前

exit - プ ロ セ ス の 正 常 終 了

書 式

#include <stdlib.h>

void exit(int status );

説 明

exit () 関 数 は 、 プ ロ セ ス を 正 常 に 終 了 さ せ 、 status の 最 下 位 バ イ ト (つ ま り status & 0xFF ) を 親 プ ロ セ ス へ 返 す ( wait (2) を 参 照 )。

atexit (3) や on_exit (3) に よ っ て 登 録 さ れ た 全 て の 関 数 は 、 そ れ ら が 登 録 さ れ た 順 番 と 逆 順 に コ ー ル さ れ る 。 (登 録 さ れ た 関 数 の 中 で atexit (3) or on_exit (3) を 使 っ て exit 処 理 中 に 実 行 さ れ る 追 加 の 関 数 を 登 録 す る こ と が で き る ; 新 規 に 登 録 さ れ た 関 数 は 、 こ の 後 で 実 行 さ れ る 関 数 リ ス ト の 先 頭 に 追 加 さ れ る 。 ) こ れ ら の 関 数 の 一 つ が 返 ら な か っ た 場 合 (例 え ば 、 そ の 関 数 が _exit (2) を 呼 び 出 し た り 、 シ グ ナ ル で 自 分 自 身 を kill し た 場 合 )、 残 り の 関 数 は ど れ も 呼 び 出 さ れ ず 、 そ れ 以 降 の exit 処 理 (特 に stdio (3) ス ト リ ー ム の フ ラ ッ シ ュ な ど ) は 中 止 さ れ る 。 あ る 関 数 が atexit (3) や on_exit (3) を 使 っ て 複 数 回 登 録 さ れ て い た 場 合 、 そ の 関 数 は 登 録 さ れ た の と 同 じ 回 数 だ け 呼 び 出 さ れ る 。

オ ー プ ン 中 の stdio (3) ス ト リ ー ム は 全 て フ ラ ッ シ ュ さ れ て 、 ク ロ ー ズ さ れ る 。 tmpfile (3) に よ っ て 作 成 さ れ た フ ァ イ ル は 削 除 さ れ る 。

C 標 準 で は EXIT_SUCCESS EXIT_FAILURE と い う 2つ の 定 数 が 定 義 さ れ て い る 。 そ れ ぞ れ 正 常 終 了 と 異 常 終 了 を 示 す も の で 、 exit () と し て 渡 す こ と が で き る 。

返 り 値

exit () 関 数 は 返 ら な い 。

属 性

こ の 節 で 使 用 さ れ て い る 用 語 の 説 明 に つ い て は 、 attributes (7) を 参 照 。

Image grohtml-24236-1.png

exit () 関 数 は 保 護 さ れ て い な い グ ロ ー バ ル 変 数 を 使 用 し て い る た め 、 ス レ ッ ド セ ー フ で は な い 。

準 拠

POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.

注 意

atexit (3) や on_exit (3) を 使 っ て 登 録 さ れ た 関 数 の 中 で exit () か longjmp (3) が 呼 び 出 さ れ た 場 合 、 動 作 は 未 定 義 で あ る 。 execve (2) を 呼 び 出 す と 、 atexit (3) や on_exit (3) を 使 っ て 登 録 さ れ た 関 数 が 削 除 さ れ る 点 に 注 意 す る こ と 。

EXIT_SUCCESS EXIT_FAILURE を 使 う と 、 0 や (1 や -1 と い っ た ) 0 以 外 の 値 を 使 う の に 比 べ て (UNIX 以 外 の 環 境 に ) 移 植 す る の が い く ら か 簡 単 に な る 。 特 に VMS は 別 の 方 式 を 用 い て い る 。

BSD は 終 了 コ ー ド を 標 準 化 し よ う と し て い る (GNU C ラ イ ブ ラ リ な ど の い く つ か の C ラ イ ブ ラ リ も こ れ を 採 用 し て い る ); <sysexits.h> を 参 照 す る こ と 。

After exit (), the exit status must be transmitted to the parent process. There are three cases:

If the parent has set SA_NOCLDWAIT , or has set the SIGCHLD handler to SIG_IGN , the status is discarded and the child dies immediately.

If the parent was waiting on the child, it is notified of the exit status and the child dies immediately.

Otherwise, the child becomes a "zombie" process: most of the process resources are recycled, but a slot containing minimal information about the child process (termination status, resource usage statistics) is retained in process table. This allows the parent to subsequently use waitpid (2) (or similar) to learn the termination status of the child; at that point the zombie process slot is released.

SIGCHLD シ グ ナ ル の サ ポ ー ト が 実 装 さ れ て い る 場 合 、 こ の シ グ ナ ル は 親 プ ロ セ ス に 送 ら れ る 。 親 プ ロ セ ス が SA_NOCLDWAIT を 設 定 し た 場 合 、 SIGCHLD シ グ ナ ル が 送 ら れ る か ど う か は 定 義 さ れ て い な い 。

Signals sent to other processes

終 了 す る プ ロ セ ス が セ ッ シ ョ ン の リ ー ダ ー で 、 そ の プ ロ セ ス の 制 御 端 末 が そ の セ ッ シ ョ ン の 制 御 端 末 で あ る 場 合 、 こ の 制 御 端 末 の フ ォ ア グ ラ ウ ン ド プ ロ セ ス グ ル ー プ に あ る 各 プ ロ セ ス に SIGHUP シ グ ナ ル が 送 ら れ 、 端 末 が セ ッ シ ョ ン か ら 切 り 離 さ れ る 。 こ れ に よ り 新 し い 制 御 プ ロ セ ス を 取 得 す る こ と が で き る 。

プ ロ セ ス が 終 了 す る こ と に よ り 、 プ ロ セ ス グ ル ー プ が 孤 立 し て 、 そ の グ ル ー プ の メ ン バ ー の う ち の ど れ か が 停 止 し た 場 合 、 プ ロ セ ス グ ル ー プ の 各 プ ロ セ ス に 対 し て SIGHUP シ グ ナ ル が 送 ら れ 、 続 い て SIGCONT シ グ ナ ル が 送 ら れ る 。 孤 立 し た (orphaned) プ ロ セ ス グ ル ー プ の 説 明 は setpgid (2) を 参 照 。

Except in the above cases, where the signalled processes may be children of the terminating process, termination of a process does not in general cause a signal to be sent to children of that process. However, a process can use the prctl (2) PR_SET_PDEATHSIG operation to arrange that it receives a signal if its parent terminates.

関 連 項 目

_exit (2), get_robust_list (2), setpgid (2), wait (2), atexit (3), on_exit (3), tmpfile (3)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。