OSDN Git Service

(split) Import translated manuals from JM CVS Repository.
[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)