OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / draft / man2 / close.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\"                               1993 Michael Haardt, Ian Jackson.
5 .\"
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
9 .\"
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
14 .\"
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein.  The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
21 .\" professionally.
22 .\"
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
25 .\"
26 .\" Modified Wed Jul 21 22:40:25 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Sat Feb 18 15:27:48 1995 by Michael Haardt
28 .\" Modified Sun Apr 14 11:40:50 1996 by Andries Brouwer <aeb@cwi.nl>:
29 .\"   corrected description of effect on locks (thanks to
30 .\"   Tigran Aivazian <tigran@sco.com>).
31 .\" Modified Fri Jan 31 16:21:46 1997 by Eric S. Raymond <esr@thyrsus.com>
32 .\" Modified 2000-07-22 by Nicolas Lichtmaier <nick@debian.org>
33 .\"   added note about close(2) not guaranteeing that data is safe on close.
34 .\"
35 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
36 .\"         all rights reserved.
37 .\" Translated Sat Jun  1 22:22:05 JST 1997
38 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
39 .\" Modified Mon Sep 23 20:42:13 JST 2000
40 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
41 .\" Updated & Modified Sat Apr  7 03:24:03 JST 2001
42 .\"         by Yuichi SATO <ysato@h4.dion.ne.jp>
43 .\" Updated & Modified Mon Jan 14 12:41:36 JST 2002 by Yuichi SATO
44 .\" Updated & Modified Wed Dec 29 07:01:14 JST 2004
45 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>
46 .\" Updated 2007-10-12, Akihiro MOTOKI, LDP v2.66
47 .\" Updated 2008-02-10, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.77
48 .\"
49 .\"WORD:        descriptor              ディスクリプタ
50 .\"WORD:        close                   クローズ
51 .\"WORD:        lock                    ロック
52 .\"WORD:        process                 プロセス
53 .\"WORD:        quota                   クォータ
54 .\"
55 .TH CLOSE 2 2007-12-28 "Linux" "Linux Programmer's Manual"
56 .\"O .SH NAME
57 .SH 名前
58 .\"O close \- close a file descriptor
59 close \- ファイルディスクリプタをクローズする
60 .\"O .SH SYNOPSIS
61 .SH 書式
62 .nf
63 .B #include <unistd.h>
64 .sp
65 .BI "int close(int " fd );
66 .fi
67 .\"O .SH DESCRIPTION
68 .SH 説明
69 .\"O .BR close ()
70 .\"O closes a file descriptor, so that it no longer refers to any file and
71 .\"O may be reused. Any record locks (see
72 .\"O .BR fcntl (2))
73 .\"O held on the file it was associated with,
74 .\"O and owned by the process, are removed (regardless of the file
75 .\"O descriptor that was used to obtain the lock).
76 .BR close ()
77 は、ファイルディスクリプタをクローズする。
78 そのディスクリプタは、どのファイルも参照していない状態になり、
79 再利用が可能になる。
80 そのファイルディスクリプタに関連づけられたファイルに
81 かけられたレコード・ロック
82 .RB ( fcntl (2)
83 参照) のうち、そのプロセスが保有しているものは、
84 (そのファイルディスクリプタがロック取得に利用されたか
85 どうかによらず) すべて削除される。
86 .PP
87 .\"O If
88 .\"O .I fd
89 .\"O is the last file descriptor referring to the underlying
90 .\"O open file description (see
91 .\"O .BR open (2)),
92 .\"O the resources associated with the open file description are freed;
93 .\"O if the descriptor was the last reference to a file which has been
94 .\"O removed using
95 .\"O .BR unlink (2)
96 .\"O the file is deleted.
97 .I fd
98 が、対応するオープンファイル記述 (open file description)
99 .RB ( open (2)
100 参照) を参照する最後のファイルディスクリプタだった場合、
101 オープンファイル記述に関連するリソースが解放される。
102 そのディスクリプタが、
103 .B unlink
104 を使用して削除 (remove) されたファイルに対する最後の参照だった場合には、
105 そのファイルは削除 (delete) される。
106 .\"O .SH "RETURN VALUE"
107 .SH 返り値
108 .\"O .BR close ()
109 .\"O returns zero on success.
110 .\"O On error, \-1 is returned, and
111 .\"O .I errno
112 .\"O is set appropriately.
113 .BR close ()
114 は成功した場合は 0 を返す。
115 エラーが発生した場合は \-1 を返して、
116 .I errno
117 を適切に設定する。
118 .\"O .SH ERRORS
119 .SH エラー
120 .TP
121 .B EBADF
122 .\"O .I fd
123 .\"O isn't a valid open file descriptor.
124 .I fd
125 が有効なオープンされたディスクリプタでない。
126 .TP
127 .B EINTR
128 .\"O The
129 .\"O .BR close ()
130 .\"O call was interrupted by a signal; see
131 .\"O .BR signal (7).
132 .BR close ()
133 コールがシグナルにより中断 (interrupt) された。
134 .BR signal (7)
135 参照。
136 .TP
137 .B EIO
138 .\"O An I/O error occurred.
139 I/O エラーが発生した。
140 .\"O .SH "CONFORMING TO"
141 .SH 準拠
142 .\"O SVr4, 4.3BSD, POSIX.1-2001.
143 .\"O .\" SVr4 documents an additional ENOLINK error condition.
144 SVr4, 4.3BSD, POSIX.1-2001.
145 .\" SVr4, SVID, POSIX, X/OPEN, 4.3BSD に準拠する。
146 .\" SVr4 には他に ENOLINK エラー状態についての記述がある。
147 .\"O .SH "NOTES"
148 .SH 注意
149 .\"O Not checking the return value of
150 .\"O .BR close ()
151 .\"O is a common but nevertheless
152 .\"O serious programming error.
153 .\"O It is quite possible that errors on a
154 .\"O previous
155 .\"O .BR write (2)
156 .\"O operation are first reported at the final
157 .\"O .BR close ().
158 .\"O Not checking the return value when closing the file may lead to
159 .\"O silent loss of data.
160 .\"O This can especially be observed with NFS
161 .\"O and with disk quota.
162 .BR close ()
163 の返り値のチェックはよく省略されるが、
164 これは深刻なプログラミングエラーである。
165 前の
166 .BR write (2)
167 処理に関するエラーが最後の
168 .BR close ()
169 のときになって初めて通知される場合がありうる。
170 ファイルクローズの際に返り値をチェックしないと、
171 気付かないうちにデータを失ってしまうかもしれない。
172 これは特に NFS やディスク・クォータを使用した場合に見られる。
173 .PP
174 .\"O A successful close does not guarantee that the data has been successfully
175 .\"O saved to disk, as the kernel defers writes.
176 .\"O Is not common for a file system
177 .\"O to flush the buffers when the stream is closed.
178 .\"O If you need to be sure that
179 .\"O the data is physically stored use
180 .\"O .BR fsync (2).
181 .\"O (It will depend on the disk hardware at this point.)
182 クローズに成功しても、データがディスクに保存されたかどうかは
183 保証されない (カーネルが書きこみを遅延させることがあるためである)。
184 ストリームがクローズされるときにバッファをフラッシュするかどうかは、
185 ファイルシステムによって異なる。
186 データが物理的に保存されることを保証する必要がある場合には、
187 .BR fsync (2)
188 を使用すること
189 .RB ( fsync (3)
190 を行った時点で、データの保存はディスクのハードウェアに依存する
191 問題となる)。
192 .PP
193 .\"O It is probably unwise to close file descriptors while
194 .\"O they may be in use by system calls in
195 .\"O other threads in the same process.
196 .\"O Since a file descriptor may be reused,
197 .\"O there are some obscure race conditions
198 .\"O that may cause unintended side effects.
199 同じプロセス内の他のスレッドのシステムコールが使用している可能性がある間に、
200 ファイルディスクリプタをクローズするのは、おそらく賢明ではないだろう。
201 ファイルディスクリプタは再利用されるかもしれないので、
202 あいまいな競合条件となることがあり、意図しない副作用の原因となりうる。
203 .\" Date: Tue, 4 Sep 2007 13:57:35 +0200
204 .\" From: Fredrik Noring <noring@nocrew.org>
205 .\" One such race involves signals and ERESTARTSYS. If a file descriptor
206 .\" in use by a system call is closed and then reused by e.g. an
207 .\" independent open() in some unrelated thread, before the original system
208 .\" call has restared after ERESTARTSYS, the original system call will
209 .\" later restart with the reused file descriptor. This is most likely a
210 .\" serious programming error.
211 .\"O .SH "SEE ALSO"
212 .SH 関連項目
213 .BR fcntl (2),
214 .BR fsync (2),
215 .BR open (2),
216 .BR shutdown (2),
217 .BR unlink (2),
218 .BR fclose (3)