.\" 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)