1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
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.
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.
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
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified Sat Jul 24 00:06:00 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Wed Jan 17 16:02:32 1996 by Michael Haardt
28 .\" <michael@cantor.informatik.rwth-aachen.de>
29 .\" Modified Thu Apr 11 19:26:35 1996 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
31 .\" Modified Fri Jan 31 16:47:33 1997 by Eric S. Raymond <esr@thyrsus.com>
32 .\" Modified Sat Jul 12 20:45:39 1997 by Michael Haardt
33 .\" <michael@cantor.informatik.rwth-aachen.de>
35 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
36 .\" all rights reserved.
37 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Modified 1997-09-28, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
39 .\" Updated & Modified 2005-02-24, Yuichi SATO <ysato444@yahoo.co.jp>
40 .\" Updated 2005-09-06, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
41 .\" Updated 2005-10-14, Akihiro MOTOKI
42 .\" Updated 2008-02-10, Akihiro MOTOKI, LDP v2.77
43 .\" Updated 2009-04-13, Akihiro MOTOKI, LDP v3.20
45 .\"WORD: descriptor ディスクリプター
48 .\"WORD: process group プロセス・グループ
49 .\"WORD: backgraound バックグランド
52 .\"WORD: directory ディレクトリ
53 .\"WORD: object オブジェクト
55 .TH READ 2 2009-02-23 "Linux" "Linux Programmer's Manual"
58 .\"O read \- read from a file descriptor
59 read \- ファイル・ディスクリプターから読み込む
63 .B #include <unistd.h>
65 .BI "ssize_t read(int " fd ", void *" buf ", size_t " count );
70 .\"O attempts to read up to
72 .\"O bytes from file descriptor
74 .\"O into the buffer starting at
77 はファイル・ディスクリプター (file descriptor)
89 .\"O returns zero and has no other results.
94 .\"O the result is unspecified.
103 .\"O .SH "RETURN VALUE"
105 .\"O On success, the number of bytes read is returned (zero indicates end of
106 .\"O file), and the file position is advanced by this number.
107 .\"O It is not an error if this number is smaller than the number of bytes
108 .\"O requested; this may happen for example because fewer bytes are actually
109 .\"O available right now (maybe because we were close to end-of-file, or
110 .\"O because we are reading from a pipe, or from a terminal), or because
112 .\"O was interrupted by a signal.
113 成功した場合、読み込んだバイト数を返す (0 はファイルの終りを意味する)。
115 この数が要求した数より小さかったとしてもエラーではない;
116 例えば今すぐには実際にそれだけの数しかない場合 (ファイルの最後に近いのかも
117 しれないし、パイプ (pipe) や端末 (terminal) から読み込んでいるかもしれない) や
119 がシグナル (signal) によって割り込まれた場合にこれは起こりえる。
120 .\"O On error, \-1 is returned, and
122 .\"O is set appropriately.
123 .\"O In this case it is left unspecified whether
124 .\"O the file position (if any) changes.
127 が適切に設定される。この場合はファイル位置が変更されるかどうかは
132 .\"O The file descriptor
134 .\"O refers to a file other than a socket and has been marked nonblocking
135 .\"O .RB ( O_NONBLOCK ),
136 .\"O and the read would block.
140 非停止 (nonblocking) モード
142 に設定されており、読み込みを行うと停止する状況にある。
144 .\"O .BR EAGAIN " or " EWOULDBLOCK
145 .BR EAGAIN " または " EWOULDBLOCK
146 .\" Actually EAGAIN on Linux
147 .\"O The file descriptor
149 .\"O refers to a socket and has been marked nonblocking
150 .\"O .RB ( O_NONBLOCK ),
151 .\"O and the read would block.
152 .\"O POSIX.1-2001 allows either error to be returned for this case,
153 .\"O and does not require these constants to have the same value,
154 .\"O so a portable application should check for both possibilities.
157 がソケットを参照していて、非停止 (nonblocking) モード
159 に設定されており、読み込みを行うと停止する状況にある。
160 POSIX.1-2001 は、この場合にどちらのエラーを返すことも認めており、
161 これら 2 つの定数が同じ値を持つことも求めていない。
162 したがって、移植性が必要なアプリケーションでは、両方の可能性を
167 .\"O is not a valid file descriptor or is not open for reading.
169 が有効なファイル・ディスクリプターでないか、読み込みのために
174 .\"O is outside your accessible address space.
179 .\"O The call was interrupted by a signal before any data was read; see
181 何のデータも読み込まないうちにシグナルに割り込まれた。
187 .\"O is attached to an object which is unsuitable for reading;
188 .\"O or the file was opened with the
190 .\"O flag, and either the address specified in
192 .\"O the value specified in
194 .\"O or the current file offset is not suitably aligned.
196 は読み込みに適していないオブジェクトを参照している。
209 .\"O was created via a call to
210 .\"O .BR timerfd_create (2)
211 .\"O and the wrong size buffer was given to
214 .\"O .BR timerfd_create (2)
215 .\"O for further information.
218 .BR timerfd_create (2)
223 .BR timerfd_create (2)
228 .\"O This will happen for example when the process is in a
229 .\"O background process group, tries to read from its controlling tty,
230 .\"O and either it is ignoring or blocking
232 .\"O or its process group
234 .\"O It may also occur when there is a low-level I/O error
235 .\"O while reading from a disk or tape.
236 I/O エラー。これは例えばプロセスがバックグランド・プロセス・グループで、
237 それを制御している tty から読み込もうとし、
239 が無視 (ignore) または禁止 (blocking) されている場合や、
240 そのプロセス・グループが孤立 (orphan) している場合に起こる。
241 またディスクやテープを読んでいる時に低レベル I/O エラー
246 .\"O refers to a directory.
250 .\"O Other errors may occur, depending on the object connected to
253 が接続しているオブジェクトによっては他のエラーも起こりえる。
256 .\"O that is interrupted after reading some data
257 .\"O to return \-1 (with
261 .\"O or to return the number of bytes already read.
263 いくらかのデータを読んだ後に割り込みが起こった場合、
271 .\"O .SH "CONFORMING TO"
273 SVr4, 4.3BSD, POSIX.1-2001.
276 .\"O On NFS file systems, reading small amounts of data will only update the
277 .\"O timestamp the first time, subsequent calls may not do so.
279 .\"O by client side attribute caching, because most if not all NFS clients
280 .\"O leave st_atime (last file access time)
281 .\"O updates to the server and client side reads satisfied from the
282 .\"O client's cache will not cause st_atime updates on the server as there are no
283 .\"O server side reads.
284 .\"O UNIX semantics can be obtained by disabling client
285 .\"O side attribute caching, but in most situations this will substantially
286 .\"O increase server load and decrease performance.
287 NFS において。少量のデータを読み込む場合、最初の時のみにタイム
288 スタンプが更新され、続くコールでは更新されないだろう。
289 これはクライアント側で属性のキャッシングを行なうためである。
290 なぜならば、もし全ての NFS クライアントが st_atime (最終ファイルアクセス時刻)
291 の更新をサーバーに送らず、クライアント側でキャッシュを読むことに満足して
292 いれば、サーバー側での read は発生しないので st_atime の更新は行なわれからだ。
293 UNIX の方式では、クライアント側の属性のキャッシングを無効にすることで、
294 これを得ることができる。しかしほとんどの状況ではこれは続くサーバーの
295 負荷を増加させ、パフォーマンスの低下をもたらす。
297 .\"O Many file systems and disks were considered to be fast enough that the
298 .\"O implementation of
300 .\"O was deemed unnecessary.
303 .\"O may not be available on files
307 の実装はしなくても済むくらいに十分に高速であると考えられている。