OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / brk.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright (c) 1993 Michael Haardt
4 .\" (michael@moria.de),
5 .\" Fri Apr  2 11:32:09 MET DST 1993
6 .\"
7 .\" This is free documentation; you can redistribute it and/or
8 .\" modify it under the terms of the GNU General Public License as
9 .\" published by the Free Software Foundation; either version 2 of
10 .\" the License, or (at your option) any later version.
11 .\"
12 .\" The GNU General Public License's references to "object code"
13 .\" and "executables" are to be interpreted as the output of any
14 .\" document formatting or typesetting system, including
15 .\" intermediate and printed output.
16 .\"
17 .\" This manual is distributed in the hope that it will be useful,
18 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 .\" GNU General Public License for more details.
21 .\"
22 .\" You should have received a copy of the GNU General Public
23 .\" License along with this manual; if not, write to the Free
24 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
25 .\" USA.
26 .\"
27 .\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu>
29 .\"
30 .\" Japanese Version Copyright (c) 1996 TABATA Tomohira
31 .\"         all rights reserved.
32 .\" Translated Wed Jun 26 19:12:54 JST 1996
33 .\"         by TABATA Tomohira <loba@k2.t.u-tokyo.ac.jp>
34 .\" Modified Sat Dec 13 23:43:56 JST 1997
35 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
36 .\" Updated & Modified Wed May 19 01:55:29 JST 2004
37 .\"         by Yuichi SATO <ysato444@yahoo.co.jp>, LDP v1.66
38 .\" Updated & Modified Tue Jan  2 09:09:47 JST 2007 by Yuichi SATO, LDP v2.43
39 .\" Updated 2008-08-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
40 .\"
41 .TH BRK 2 2008-06-18 "Linux" "Linux Programmer's Manual"
42 .\"O .SH NAME
43 .SH Ì¾Á°
44 .\"O brk, sbrk \- change data segment size
45 brk, sbrk \- ¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤Î¥µ¥¤¥º¤ÎÊѹ¹¤¹¤ë
46 .\"O .SH SYNOPSIS
47 .SH ½ñ¼°
48 .B #include <unistd.h>
49 .sp
50 .BI "int brk(void *" addr );
51 .sp
52 .BI "void *sbrk(intptr_t " increment );
53 .sp
54 .in -4n
55 .\"O Feature Test Macro Requirements for glibc (see
56 .\"O .BR feature_test_macros (7)):
57 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
58 .RB ( feature_test_macros (7)
59 »²¾È):
60 .in
61 .sp
62 .ad l
63 .BR brk (),
64 .BR sbrk ():
65 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500
66 .ad b
67 .\"O .SH DESCRIPTION
68 .SH ÀâÌÀ
69 .\"O .BR brk ()
70 .\"O and
71 .\"O .BR sbrk ()
72 .\"O change the location of the
73 .\"O .IR "program break" ,
74 .\"O which defines the end of the process's data segment
75 .\"O (i.e., the program break is the first location after the end of the
76 .\"O uninitialized data segment).
77 .\"O Increasing the program break has the effect of
78 .\"O allocating memory to the process;
79 .\"O decreasing the break deallocates memory.
80 .BR brk ()
81 ¤È
82 .BR sbrk ()
83 ¤Ï
84 .I "¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯ (program break)"
85 ¤Î¾ì½ê¤òÊѹ¹¤¹¤ë¡£
86 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤Ï¥×¥í¥»¥¹¤Î¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È (data segment) ¤Î
87 ËöÈø¤ò¼¨¤¹ (¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤Ï¡¢½é´ü²½¤µ¤ì¤Æ¤¤¤Ê¤¤
88 ¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤ÎËöÈø¤Îľ¸å¤Î¾ì½ê¤È¤Ê¤ë)¡£
89 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤òÁý¤ä¤¹¤È¤¤¤¦¤³¤È¤Ï¡¢¤½¤Î¥×¥í¥»¥¹¤Ø¤Î
90 ¥á¥â¥ê¤ò³ä¤êÅö¤Æ¤ë¸ú²Ì¤¬¤¢¤ê¡¢
91 ¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤ò¸º¤é¤¹¤È¤¤¤¦¤³¤È¤Ï¡¢¥á¥â¥ê¤ò²òÊü¤¹¤ë
92 ¤È¤¤¤¦¤³¤È¤Ç¤¢¤ë¡£
93
94 .\"O .BR brk ()
95 .\"O sets the end of the data segment to the value specified by
96 .\"O .IR addr ,
97 .\"O when that value is reasonable, the system has enough memory,
98 .\"O and the process does not exceed its maximum data size (see
99 .\"O .BR setrlimit (2)).
100 .BR brk ()
101 ¤Ï¡¢¥Ç¡¼¥¿¡¦¥»¥°¥á¥ó¥È¤ÎËöÈø¤ò
102 .I addr
103 ¤Ç»ØÄꤷ¤¿ÃͤËÀßÄꤹ¤ë¡£
104 ÀßÄ꤬¹Ô¤ï¤ì¤ë¤Î¤Ï¡¢»ØÄꤷ¤¿Ãͤ¬Í­¸ú¤Ç¡¢
105 ¥·¥¹¥Æ¥à¤Ë½½Ê¬¤Ê¥á¥â¥ê¤¬¤¢¤ê¡¢
106 ¥×¥í¥»¥¹¤Î¥Ç¡¼¥¿¥µ¥¤¥º¤ÎºÇÂçÃͤòĶ¤¨¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ç¤¢¤ë
107 .RB ( setrlimit (2)
108 ¤ò»²¾È)¡£
109
110 .\"O .BR sbrk ()
111 .\"O increments the program's data space by
112 .\"O .I increment
113 .\"O bytes.
114 .BR sbrk ()
115 ¤Ï¡¢¥×¥í¥°¥é¥à¤Î¥Ç¡¼¥¿¶õ´Ö¤ò
116 .I increment
117 ¥Ð¥¤¥È¤À¤±Áý¤ä¤¹¡£
118 .\"O Calling
119 .\"O .BR sbrk ()
120 .\"O with an
121 .\"O .I increment
122 .\"O of 0 can be used to find the current location of the program break.
123 .I increment
124 ¤ò 0 ¤Ë¤·¤Æ
125 .BR sbrk ()
126 ¤ò¸Æ¤Ó½Ð¤¹¤³¤È¤Ç¡¢¥×¥í¥°¥é¥à¤Î¸½ºß¤Î¥Ö¥ì¡¼¥¯ (break) ¾ì½ê¤òÃΤ뤳¤È¤¬¤Ç¤­¤ë¡£
127 .\"O .SH "RETURN VALUE"
128 .SH ÊÖ¤êÃÍ
129 .\"O On success,
130 .\"O .BR brk ()
131 .\"O returns zero.
132 À®¸ù¤·¤¿¾ì¹ç¡¢
133 .BR brk ()
134 ¤Ï 0 ¤òÊÖ¤¹¡£
135 .\"O On error, \-1 is returned, and
136 .\"O .I errno
137 .\"O is set to
138 .\"O .BR ENOMEM .
139 .\"O (But see \fILINUX NOTES\fP below.)
140 ¥¨¥é¡¼¤Î¾ì¹ç¤Ë¤Ï¡¢\-1 ¤òÊÖ¤·¡¢
141 .I errno
142 ¤Ë
143 .B ENOMEM
144 ¤òÀßÄꤹ¤ë
145 (¤¿¤À¤·¡ÖLINUX ¤Ç¤ÎÃí°Õ¡×¤ò»²¾È¤¹¤ë¤³¤È)¡£
146
147 .\"O On success,
148 .\"O .BR sbrk ()
149 .\"O returns the previous program break.
150 .\"O (If the break was increased,
151 .\"O then this value is a pointer to the start of the newly allocated memory).
152 .\"O On error,
153 .\"O .I "(void\ *)\ \-1"
154 .\"O is returned, and
155 .\"O .I errno
156 .\"O is set to
157 .\"O .BR ENOMEM .
158 À®¸ù¤·¤¿¾ì¹ç¡¢
159 .BR sbrk ()
160 ¤ÏÊѹ¹Á°¤Î¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤òÊÖ¤¹
161 (¥×¥í¥°¥é¥à¡¦¥Ö¥ì¡¼¥¯¤¬Áý¤ä¤µ¤ì¤¿¾ì¹ç¡¢¤³¤ÎÃͤÏ
162 ¿·¤·¤¯³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤ÎÀèƬ¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤È¤Ê¤ë)¡£
163 ¥¨¥é¡¼¤Î¾ì¹ç¤Ë¤Ï¡¢
164 .I "(void\ *)\ \-1"
165 ¤òÊÖ¤·¡¢
166 .I errno
167 ¤Ë
168 .B ENOMEM
169 ¤òÀßÄꤹ¤ë¡£
170 .\"O .SH "CONFORMING TO"
171 .SH ½àµò
172 .\"O 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
173 4.3BSD, SUSv1.
174 SUSv2 ¤Ç¤Ï¡Ö²áµî¤Î̾»Ä (LEGACY)¡×¤È°ÌÃÖÉÕ¤±¤é¤ì¤Æ¤ª¤ê¡¢
175 POSIX.1-2001 ¤Çºï½ü¤µ¤ì¤¿¡£
176 .\"O .\"
177 .\"O .\" .BR brk ()
178 .\"O .\" and
179 .\"O .\" .BR sbrk ()
180 .\"O .\" are not defined in the C Standard and are deliberately excluded from the
181 .\"O .\" POSIX.1-1990 standard (see paragraphs B.1.1.1.3 and B.8.3.3).
182 .\" .BR brk ()
183 .\" ¤È
184 .\" .BR sbrk ()
185 .\" ¤Ï C µ¬³Ê (C Standard) ¤Ë¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
186 .\" ¤Þ¤¿ POSIX.1 µ¬³Ê¤«¤é¤Ï°Õ¿ÞŪ¤Ë½ü³°¤µ¤ì¤Æ¤¤¤ë (ÃÊÍî B.1.1.1.3, B.8.3.3 »²¾È)¡£
187 .\"O .SH NOTES
188 .SH Ãí°Õ
189 .\"O Avoid using
190 .\"O .BR brk ()
191 .\"O and
192 .\"O .BR sbrk ():
193 .\"O the
194 .\"O .BR malloc (3)
195 .\"O memory allocation package is the
196 .\"O portable and comfortable way of allocating memory.
197 .BR brk ()
198 ¤ä
199 .BR sbrk ()
200 ¤ò»ÈÍѤ¹¤ë¤Î¤ÏÈò¤±¤ë¤³¤È¡£
201 .BR malloc (3)
202 ¥á¥â¥ê³ä¤êÅö¤Æ¥Ñ¥Ã¥±¡¼¥¸¤ÎÊý¤¬¡¢°Ü¿¢À­¤¬¹â¤¯¡¢
203 »È¤¤¤ä¤¹¤¤¥á¥â¥ê³ä¤êÅö¤ÆÊýË¡¤òÄ󶡤·¤Æ¤¤¤ë¡£
204
205 .\"O Various systems use various types for the argument of
206 .\"O .BR sbrk ().
207 ¤¤¤í¤¤¤í¤Ê¥·¥¹¥Æ¥à¤Ë¤ª¤¤¤Æ¡¢
208 .BR sbrk ()
209 ¤Î°ú¤­¿ô¤ËÍÍ¡¹¤Ê·¿¤¬»È¤ï¤ì¤Æ¤¤¤ë¡£
210 .\"O Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP.
211 °ìÈÌŪ¤Ê¤Î¤Ï \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP ¤Ç¤¢¤ë¡£
212 .\"O .\" One sees
213 .\"O .\" \fIint\fP (e.g., XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
214 .\"O .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
215 .\"O .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
216 .\"O .\" \fIintptr_t\fP (e.g., XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6,
217 .\"O .\" Tru64 5.1, glibc2.2).
218 .\" \fIint\fP (¤¿¤È¤¨¤Ð XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
219 .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
220 .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
221 .\" \fIintptr_t\fP (¤¿¤È¤¨¤Ð XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7,
222 .\" NetBSD 1.6, Tru64 5.1, glibc2.2).
223 .\" ¤È¤¤¤¦¤Î¤¬Ê¬¤«¤ë¤À¤í¤¦¡£
224 .\"O .SS Linux Notes
225 .SS Linux ¤Ç¤ÎÃí°Õ
226 .\"O The return value described above for
227 .\"O .BR brk ()
228 .\"O is the behavior provided by the glibc wrapper function for the Linux
229 .\"O .BR brk ()
230 .\"O system call.
231 ¾å¤ÇÀâÌÀ¤·¤¿
232 .BR brk ()
233 ¤ÎÊÖ¤êÃͤˤĤ¤¤Æ¤ÎÆ°ºî¤Ï¡¢
234 Linux ¤Î
235 .BR brk ()
236 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò¥é¥Ã¥×¤¹¤ë glibc ¤Î´Ø¿ô¤Ë¤è¤ë¤â¤Î¤Ç¤¢¤ë¡£
237 .\"O (On most other implementations, the return value from
238 .\"O .BR brk ()
239 .\"O is the same; this return value was also specified in SUSv2.)
240 (¤½¤Î¾¤Î¿¤¯¤Î¼ÂÁõ¤Ç¤â¡¢
241 .BR brk ()
242 ¤ÎÊÖ¤êÃͤϤ³¤ì¤ÈƱ¤¸¤Ç¤¢¤ë¡£
243 ¤³¤ÎÊÖ¤êÃͤϠSUSv2 ¤Ç¤âµ¬Äꤵ¤ì¤Æ¤¤¤ë¡£)
244 .\"O However,
245 .\"O the actual Linux system call returns the new program break on success.
246 ¤·¤«¤·¡¢¼ÂºÝ¤Î Linux ¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¡¢À®¸ù¤·¤¿¾ì¹ç¡¢
247 ¥×¥í¥°¥é¥à¤Î¿·¤·¤¤¥Ö¥ì¡¼¥¯¤òÊÖ¤¹¡£
248 .\"O On failure, the system call returns the current break.
249 ¼ºÇÔ¤·¤¿¾ì¹ç¡¢¤³¤Î¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ï¸½ºß¤Î¥Ö¥ì¡¼¥¯¤òÊÖ¤¹¡£
250 .\"O The glibc wrapper function does some work
251 .\"O (i.e., checks whether the new break is less than
252 .\"O .IR addr )
253 .\"O to provide the 0 and \-1 return values described above.
254 glibc ¥é¥Ã¥Ñ¡¼´Ø¿ô¤ÏƱÍͤÎƯ¤­¤ò¤·
255 (¤¹¤Ê¤ï¤Á¡¢¿·¤·¤¤¥Ö¥ì¡¼¥¯¤¬
256 .I addr
257 ¤è¤ê¾®¤µ¤¤¤«¤É¤¦¤«¤ò¥Á¥§¥Ã¥¯¤·)¡¢
258 ¾å¤ÇÀâÌÀ¤·¤¿ 0 ¤È \-1 ¤È¤¤¤¦ÊÖ¤êÃͤòÊÖ¤¹¡£
259
260 .\"O On Linux,
261 .\"O .BR sbrk ()
262 .\"O is implemented as a library function that uses the
263 .\"O .BR brk ()
264 .\"O system call, and does some internal bookkeeping so that it can
265 .\"O return the old break value.
266 Linux ¤Ç¤Ï
267 .BR sbrk ()
268 ¤Ï
269 .BR brk ()
270 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤ò»È¤¦¥é¥¤¥Ö¥é¥ê´Ø¿ô¤È¤·¤Æ¼ÂÁõ¤µ¤ì¤Æ¤ª¤ê¡¢
271 °ÊÁ°¤Î¥Ö¥ì¡¼¥¯¤ÎÃͤòÊÖ¤¹¤³¤È¤¬¤Ç¤­¤ë¤è¤¦¤ËÆâÉô¤ÇÄ´À°¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë¡£
272 .\"O .SH "SEE ALSO"
273 .SH ´ØÏ¢¹àÌÜ
274 .BR execve (2),
275 .BR getrlimit (2),
276 .BR end (3),
277 .BR malloc (3)