1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt, Ian Jackson.
5 .\" and Copyright (C) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" Modified Sat Jul 24 13:35:59 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sun Nov 28 17:19:01 1993 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified Sat Jan 13 12:58:08 1996 by Michael Haardt
30 .\" <michael@cantor.informatik.rwth-aachen.de>
31 .\" Modified Sun Jul 21 18:59:33 1996 by Andries Brouwer <aeb@cwi.nl>
32 .\" 2001-12-13 added remark by Zack Weinberg
34 .\" Added details about seekable files and file offset.
35 .\" Noted that write() may write less than 'count' bytes, and
36 .\" gave some examples of why this might occur.
37 .\" Noted what happens if write() is interrupted by a signal.
39 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
40 .\" all rights reserved.
41 .\" Translated Tue Mar 4 00:18:20 JST 1997
42 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
43 .\" Updated & Modified Wed Jun 13 20:57:55 JST 2001
44 .\" by Yuichi SATO <ysato@h4.dion.ne.jp>
45 .\" Updated Mon Jun 25 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
46 .\" Updated Fri Dec 21 JST 2001 by Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2002-09-24 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
48 .\" Updated 2005-10-14 by Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
49 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
50 .\" Updated 2007-09-01, Akihiro MOTOKI, LDP v2.64
51 .\" Updated 2008-04-13, Akihiro MOTOKI, LDP v3.20
53 .\"WORD: descriptor ¥Ç¥£¥¹¥¯¥ê¥×¥¿
54 .\"WORD: buffer ¥Ð¥Ã¥Õ¥¡¡¼
55 .\"WORD: file system ¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à
56 .\"WORD: object ¥ª¥Ö¥¸¥§¥¯¥È
58 .\"WORD: socket ¥½¥±¥Ã¥È
59 .\"WORD: signal ¥·¥°¥Ê¥ë
60 .\"WORD: catch Êá³Í(catch)
61 .\"WORD: block Ää»ß(block)
62 .\"WORD: interrupt ³ä¤ê¹þ¤ß
63 .\"WORD: nonblocking I/O ÈóÄä»ß I/O
64 .\"WORD: device ¥Ç¥Ð¥¤¥¹
65 .\"WORD: low-level I/O Äã¥ì¤Ù¥ë I/O
67 .TH WRITE 2 2009-02-23 "Linux" "Linux Programmer's Manual"
69 write \- ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿ (file descriptor) ¤Ë½ñ¤¹þ¤à
71 .B #include <unistd.h>
73 .BI "ssize_t write(int " fd ", const void *" buf ", size_t " count );
78 ¤¬»Ø¤¹¥Ð¥Ã¥Õ¥¡¤«¤é¡¢¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
80 ¤¬»²¾È¤¹¤ë¥Õ¥¡¥¤¥ë¤Ø¡¢ºÇÂç
84 ½ñ¤¹þ¤Þ¤ì¤ë¥Ð¥¤¥È¿ô¤Ï
86 ¤è¤ê¤â¾®¤µ¤¯¤Ê¤ë¤³¤È¤¬¤¢¤ë¡£
87 Î㤨¤Ð¡¢½ñ¤¹þ¤ßÂоݤÎʪÍý¥á¥Ç¥£¥¢¤Ë½½Ê¬¤ÊÎΰ褬¤Ê¤¤¾ì¹ç¡¢
94 ¥Ð¥¤¥È̤Ëþ¤Î½ñ¤¹þ¤ß¤¬¹Ô¤ï¤ì¤¿¸å¤Ç
95 ¸Æ¤Ó½Ð¤·¤¬¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
100 seek ²Äǽ¤Ê¥Õ¥¡¥¤¥ë (¤Ä¤Þ¤ê
102 ¤¬Å¬ÍѤǤ¤ë¥Õ¥¡¥¤¥ë¡¢Î㤨¤ÐÄ̾ï¤Î¥Õ¥¡¥¤¥ë) ¤Ç¤Ï¡¢
103 ½ñ¤¹þ¤ß¤Ï¸½ºß¤Î¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤«¤é¹Ô¤ï¤ì¡¢
104 ¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤Ï¼ÂºÝ¤Ë½ñ¤¹þ¤ß¤¬¹Ô¤ï¤ì¤¿¥Ð¥¤¥È¿ôʬ
105 ²Ã»»¤µ¤ì¤ë¡£¥Õ¥¡¥¤¥ë¤¬
109 ¤µ¤ì¤¿¾ì¹ç¡¢¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤Ï½ñ¤¹þ¤ßÁ°¤Ë
110 ¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ËÀßÄꤵ¤ì¤ë¡£
111 ¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤ÎÄ´À°¤È½ñ¤¹þ¤ßÁàºî¤Ï¥¢¥È¥ß¥Ã¥¯¤Ê½èÍý¤È¤·¤Æ
116 ¤¬¹Ô¤Ê¤ï¤ì¤¿¸å¤Ë¼Â¹Ô¤·¤¿
119 ¿·¤·¤¤¥Ç¡¼¥¿¤òÊÖ¤¹¤³¤È¤òÍ׵ᤷ¤Æ¤¤¤ë¡£
120 Á´¤Æ¤Î¥Õ¥¡¥¤¥ë¡¦¥·¥¹¥Æ¥à¤¬ POSIX ½àµò¤Ç¤Ï¤Ê¤¤ÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
122 À®¸ù¤·¤¿¾ì¹ç¡¢½ñ¤¹þ¤Þ¤ì¤¿¥Ð¥¤¥È¿ô¤¬ÊÖ¤µ¤ì¤ë
123 (¥¼¥í¤Ï²¿¤â½ñ¤¹þ¤Þ¤ì¤Ê¤«¤Ã¤¿¤³¤È¤ò¼¨¤¹)¡£
124 ¥¨¥é¡¼¤Ê¤é¤Ð \-1 ¤¬ÊÖ¤µ¤ì¡¢\fIerrno\fP ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£
126 \fIcount\fP ¤¬ 0 ¤Ç¡¢
128 ¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë (regular file) ¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
130 ¤Ï¸å½Ò¤Î¥¨¥é¡¼¤Î¤¤¤º¤ì¤«¤ò¸¡½Ð¤·¤¿¾ì¹ç¡¢¼ºÇÔ¤òÊÖ¤¹¤³¤È¤¬¤¢¤ë¡£
131 ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï¡¢
132 0 ¤òÊÖ¤·¡¢Â¾¤Ë²¿¤Î±Æ¶Á¤âÍ¿¤¨¤Ê¤¤¡£
133 \fIcount\fP ¤¬ 0 ¤Ç¡¢
135 ¤¬Ä̾ï¤Î¥Õ¥¡¥¤¥ë°Ê³°¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤ë¾ì¹ç¡¢
136 ¤½¤Î·ë²Ì¤Ïµ¬Äꤵ¤ì¤Æ¤¤¤Ê¤¤¡£
140 ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
142 ¤¬¥½¥±¥Ã¥È°Ê³°¤Î¥Õ¥¡¥¤¥ë¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢
143 ÈóÄä»ß (nonblocking) ¥â¡¼¥É
145 ¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢½ñ¤¹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
147 .BR EAGAIN " ¤Þ¤¿¤Ï " EWOULDBLOCK
148 .\" Actually EAGAIN on Linux
149 ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿
151 ¤¬¥½¥±¥Ã¥È¤ò»²¾È¤·¤Æ¤¤¤Æ¡¢ÈóÄä»ß (nonblocking) ¥â¡¼¥É
153 ¤ËÀßÄꤵ¤ì¤Æ¤ª¤ê¡¢½ñ¤¹þ¤ß¤ò¹Ô¤¦¤ÈÄä»ß¤¹¤ë¾õ¶·¤Ë¤¢¤ë¡£
154 POSIX.1-2001 ¤Ï¡¢¤³¤Î¾ì¹ç¤Ë¤É¤Á¤é¤Î¥¨¥é¡¼¤òÊÖ¤¹¤³¤È¤âǧ¤á¤Æ¤ª¤ê¡¢
155 ¤³¤ì¤é 2 ¤Ä¤ÎÄê¿ô¤¬Æ±¤¸Ãͤò»ý¤Ä¤³¤È¤âµá¤á¤Æ¤¤¤Ê¤¤¡£
156 ¤·¤¿¤¬¤Ã¤Æ¡¢°Ü¿¢À¤¬É¬Íפʥ¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ç¤Ï¡¢Î¾Êý¤Î²ÄǽÀ¤ò
161 ¤¬Í¸ú¤Ê¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¤«½ñ¤¹þ¤ß¤Î¤¿¤á¤Ë¥ª¡¼¥×¥ó
162 (open) ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
166 ¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö (address space) ¤Î³°¤Ë¤¢¤ë¡£
169 ¼ÂÁõÄêµÁ¤ÎºÇÂç¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤Þ¤¿¤Ï¥×¥í¥»¥¹¤Î¥Õ¥¡¥¤¥ë¥µ¥¤¥ºÀ©¸Â¤ò
170 Ķ¤¨¤Æ¥Õ¥¡¥¤¥ë¤Ë½ñ¤¹þ¤â¤¦¤È¤·¤¿¡£
171 ¤Þ¤¿¤Ïµö²Ä¤µ¤ì¤¿¥ª¥Õ¥»¥Ã¥ÈÃͤ賦¤òĶ¤¨¤¿Àè¤Î°ÌÃÖ¤Ë
175 ²¿¤Î¥Ç¡¼¥¿¤â½ñ¤«¤Ê¤¤´Ö¤Ë¥·¥°¥Ê¥ë¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿ (interrupt)¡£
181 ¤¬½ñ¤¹þ¤ß¤¬ÉÔŬÀڤʥª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¡£
184 ¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤¬¡¢
186 ¤Ë»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¡¢
189 ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤Î¤¤¤º¤ì¤«¤Î
190 ¥¢¥é¥¤¥ó¥á¥ó¥È¤¬ÉÔŬÀڤǤ¢¤ë¡£
193 inode ¤Î½¤ÀµÃæ¤ËÄã¥ì¤Ù¥ë (low-level) I/O ¥¨¥é¡¼¤¬È¯À¸¤·¤¿¡£
197 ¤Ë¤è¤Ã¤Æ»²¾È¤µ¤ì¤ë¥Õ¥¡¥¤¥ë¤ò´Þ¤à¥Ç¥Ð¥¤¥¹ (device) ¤Ë½½Ê¬¤Ê¶õ¤¤¬¤Ê¤¤¡£
201 ¤¬¥Ñ¥¤¥× (pipe) ¤«¥½¥±¥Ã¥È (socket) ¤ËÀܳ¤µ¤ì¤Æ¤ª¤ê¡¢
202 ¤½¤ÎÈ¿ÂЦ (Æɤ߹þ¤ß¦) ¤¬¥¯¥í¡¼¥º (close) ¤µ¤ì¤Æ¤¤¤ë¡£
203 ¤³¤ì¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤Ï¡¢½ñ¤¹þ¤ß¤ò¹Ô¤Ê¤¦¥×¥í¥»¥¹¤Ï
205 ¥·¥°¥Ê¥ë (signal)¤â¼õ¤±¤ë¡£
206 (¤·¤¿¤¬¤Ã¤Æ¡¢¥×¥í¥°¥é¥à¤¬¤³¤Î¥·¥°¥Ê¥ë¤òÊá³Í (catch)¡¢Ää»ß (block)¡¢Ìµ»ë (ignore)
207 ¤·¤¿¾ì¹ç¤Î¤ß¡¢write ¤ÎÊÖ¤êÃͤò»²¾È¤Ç¤¤ë¡£)
210 ¤ËÀܳ¤µ¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤è¤Ã¤Æ¤Ï¡¢Â¾¤Î¥¨¥é¡¼¤¬µ¯¤³¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
212 SVr4, 4.3BSD, POSIX.1-2001.
213 .\" SVr4 ¤Ë¤Ï¾¤Ë EDEADLK, ENOLCK, ENOLNK,
214 .\" ENOSR, ENXIO, ERANGE ¥¨¥é¡¼¤Ë¤Ä¤¤¤Æ¤Îµ½Ò¤¬¤¢¤ë¡£
216 SVr4 ¤Ç¤Ï write ¤¬³ä¤ê¹þ¤Þ¤ì¤ë¤È¡¢¥Ç¡¼¥¿¤¬½ñ¤¹þ¤Þ¤ì¤ëľÁ°¤Ç¤Ï¤Ê¤¯¡¢
222 ¤¬À®¸ù¤·¤ÆÊ֤äƤ¤Æ¤â¡¢¥Ç¡¼¥¿¤¬¥Ç¥£¥¹¥¯¤ËµÏ¿¤µ¤ì¤¿¤³¤È¤ò
223 Êݾڤ¹¤ë¤â¤Î¤Ç¤Ï¤Ê¤¤¡£
224 ¼ÂºÝ¡¢¥Ç¡¼¥¿¤Î¤¿¤á¤Î¥¹¥Ú¡¼¥¹¤¬³ÎÊݤµ¤ì¤¿¤³¤È¤¹¤éÊݾڤµ¤ì¤Ê¤¤¤È¤¤¤¦
225 ¥Ð¥°¤Ã¤Ý¤¤¼ÂÁõ¤â¤¢¤ë¡£
226 ¤³¤ì¤ò³Î¼Â¤Ë¤¹¤ëÍ£°ì¤ÎÊýË¡¤Ï¡¢
227 Á´¤Æ¤Î¥Ç¡¼¥¿¤ò write ¤·¤¿¸å¤Ë
229 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¤¢¤ë¡£
232 ¤¬ 1 ¥Ð¥¤¥È¤â½ñ¤¹þ¤Þ¤Ê¤¤¤¦¤Á¤Ë¥·¥°¥Ê¥ë¥Ï¥ó¥É¥é¤Ë¤è¤ê³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
237 1¥Ð¥¤¥È¤Ç¤â½ñ¤¹þ¤ó¤À¸å¤Ç³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
239 ¤ÏÀ®¸ù¤·¡¢½ñ¤¹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹¡£