.\" Hey Emacs! This file is -*- nroff -*- source. .\" .\" This manpage is Copyright (C) 1992 Drew Eckhardt; .\" 1993 Michael Haardt, Ian Jackson. .\" .\" 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. .\" .\" Modified Wed Jul 21 22:40:25 1993 by Rik Faith .\" Modified Sat Feb 18 15:27:48 1995 by Michael Haardt .\" Modified Sun Apr 14 11:40:50 1996 by Andries Brouwer : .\" corrected description of effect on locks (thanks to .\" Tigran Aivazian ). .\" Modified Fri Jan 31 16:21:46 1997 by Eric S. Raymond .\" Modified 2000-07-22 by Nicol醩 Lichtmaier .\" added note about close(2) not guaranteeing that data is safe on close. .\" .TH CLOSE 2 1996-04-14 "" "Linux Programmer's Manual" .SH NAME 名字 close \- 關閉一個檔案描述符 .SH SYNOPSIS 總覽 .nf .B #include .sp .BI "int close(int " fd ); .fi .SH DESCRIPTION 描述 .B close 關閉 一個 檔案 描述符 , 使它 不在 指向 任何 檔案 和 可以 在 新的 檔案 操作 中 被 再次 使用. 任何 與 此 檔案 相關聯 的 以及 程式 所 擁有 的 鎖 , 都 會 被 刪除 (忽略 那些 持有 鎖 的 檔案描述符) .PP 假如 .I fd 是 最後 一個 檔案描述符 與此 資源 相 關聯 , 則 這個 資源 將 被 釋放. 若此 描述符 是 最後 一個 引用 到 此 檔案 上 的 , 則 檔案 將 使用 .BR unlink (2) 刪除. .SH "RETURN VALUE" 返回值 .B close 返回 0 表示 成功 , 或者 -1 表示 有 錯誤 發生 . .SH ERRORS 錯誤資訊 .TP .B EBADF .I fd 不是 一個 有效 的 已 被 開啟 的 檔案 的 描述符 .TP .B EINTR The .BR close () 呼叫 被 一 訊號 中斷. .TP .B EIO I/O 有 錯誤 發生 .SH "CONFORMING TO" SVr4, SVID, POSIX, X/OPEN, BSD 4.3. SVr4 documents an additional ENOLINK error condition. .SH NOTES 注意 通常 不檢測 返回值 , 除了 發生 嚴重 的 程式 錯誤. 檔案系統 使用 了 "write-behind" 的 技術 提高 了 執行 .BR write (2) 時 的 效能 . 即使 還 沒有 被 寫 , 寫操作 也會 成功 . 錯誤 資訊 在 寫操作 以後 報告 , 但是 這 保證 在 關閉 檔案 時 報告 . 在 關閉 檔案 時 不檢測 返回值 可能 會 導致 資料 的 丟失 . 這 一點 在 NFS 和 磁碟 配額 上 比較 明顯. .PP 由於 核心 會 延遲 寫 , 所以 就算 成功 關閉 一個 檔案 不能 保證 資料 被 成功 的 寫到 磁碟 上. 當 檔案流 關閉 時 , 對 檔案系統 來說 一般 不去 重新整理 緩衝區 . 如果 你 要 保證 資料 寫入 磁碟 等 物理 存貯器 中 就 使用 fsync(2) 或 sync(2), 他們 會 做到 你想做的 (對於 這一點 要 依賴於 磁碟 裝置). .SH "SEE ALSO" 參考 .BR open (2), .BR fcntl (2), .BR shutdown (2), .BR unlink (2), .BR fclose (3) .SH [中文維護] Daniel (badlong@163.com) .SH [中文更新] 2002/1/10 .SH [說明] 若 發現 錯誤 或 不足 請 與 我 聯絡..SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR