.\" Copyright (C) 2001 Andries Brouwer . .\" .\" 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. .\" .TH EXIT 3 2001-11-17 "" "Linux Programmer's Manual" .SH NAME exit \- 使程式正常中止 .SH "SYNOPSIS 總覽" .nf .B #include .sp .BI "void exit(int " status ); .fi .SH "DESCRIPTION 描述" 函式 \fBexit()\fP 使得程式正常中止,\fIstatus & 0377\fP 的值被返回給父程序 (參見 .BR wait (2)) 。所有用 \fBatexit()\fP 和 \fBon_exit()\fP 註冊的函式都以與註冊時相反的順序被依次執行。使用 \fItmpfile()\fP 建立的檔案被刪除。 .LP C 標準定義了兩個值 \fIEXIT_SUCCESS\fP 和 \fIEXIT_FAILURE\fP,可以作為 \fBexit()\fP 的引數,來分別指示是否為成功退出。 .SH "RETURN VALUE 返回值" 函式 \fBexit()\fP 不會返回。 .SH "CONFORMING TO 標準參考" SVID 3, POSIX, BSD 4.3, ISO 9899 (``ANSI C'') .SH "NOTES 要點" 在 exit 處理過程中,可能會使用 \fBatexit()\fP 和 \fBon_exit()\fP 註冊其他的函式。通常,最後註冊的函式被從已註冊函式鏈中摘下來,然後執行。如果在處理過程中,又呼叫了 \fBexit()\fP 或 \fBlongjmp()\fP,那麼發生的行為是未定義的。 .LP 相對於使用 0 和非零值 1 或 \-1,使用 EXIT_SUCCESS 和 EXIT_FAILURE 可以稍微增加一些可移植性 (對非 Unix 環境)。特別的,VMS 使用一種不同的約定。 .LP BSD 試圖標準化退出程式碼 - 參見檔案 .IR 。 .LP \fBexit()\fP 之後,退出狀態必須傳遞給父程序。這裡有三種情況。如果父程序已設定了 SA_NOCLDWAIT,或者已將 SIGCHLD 的處理控制代碼設定成了 SIG_IGN,這個狀態將被忽略。這時要退出的程序立即消亡。如果父程序沒有表示它對退出狀態不感興趣,僅僅是不再等待,那麼要退出的程式變成一個殭屍程序 (``zombie'',除了包含一個位元組的退出狀態外,什麼也不是)。這樣在父程序後來呼叫 \fIwait()\fP 函式族之一時,可以得到退出狀態。 .LP 如果所用實現支援 SIGCHLD 訊號,訊號將被髮送到父程序。如果父程序已設定了 SA_NOCLDWAIT,它被取消定義。(?) .LP 如果程序是一個 session leader,它的控制終端是會話的控制終端,那麼這個終端的前臺程序組的每個程序都將收到 SIGHUP 訊號;終端將與這個會話斷開,可以再被一個新的控制程序獲得。 .LP 如果程序的退出使得一個程序組成為孤兒,並且這個新近成為孤兒的程序組中任何的程序被中止,程序組中所有的程序將依次收到 SIGHUP 和 SIGCONT 訊號。 .SH "SEE ALSO 參見" .BR _exit (2), .BR wait (2), .BR atexit (3), .BR on_exit (3), .BR tmpfile (3) .SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR