oracular (3) exit.3.gz

Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       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_SUCCESSEXIT_FAILURE という 2つの定数が 定義されている。それぞれ正常終了と異常終了を示
       すもので、 exit()  として渡すことができる。

返り値

       exit()  関数は返らない。

属性

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

       ┌─────────────────┬───────────────┬─────────────────────┐
       │インターフェース属性                  │
       ├─────────────────┼───────────────┼─────────────────────┤
       │exit()           │ Thread safety │ MT-Unsafe race:exit │
       └─────────────────┴───────────────┴─────────────────────┘
       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_SUCCESSEXIT_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/ に書かれている。