1 .\" Copyright (c) 1993 Michael Haardt, (michael@moria.de)
2 .\" and Copyright 2006, 2008, Michael Kerrisk <tmk.manpages@gmail.com>
3 .\" Fri Apr 2 11:32:09 MET DST 1993
5 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
6 .\" This is free documentation; you can redistribute it and/or
7 .\" modify it under the terms of the GNU General Public License as
8 .\" published by the Free Software Foundation; either version 2 of
9 .\" the License, or (at your option) any later version.
11 .\" The GNU General Public License's references to "object code"
12 .\" and "executables" are to be interpreted as the output of any
13 .\" document formatting or typesetting system, including
14 .\" intermediate and printed output.
16 .\" This manual is distributed in the hope that it will be useful,
17 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
18 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 .\" GNU General Public License for more details.
21 .\" You should have received a copy of the GNU General Public
22 .\" License along with this manual; if not, see
23 .\" <http://www.gnu.org/licenses/>.
26 .\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu>
27 .\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu>
29 .TH BRK 2 2021-03-22 "Linux" "Linux Programmer's Manual"
31 brk, sbrk \- change data segment size
34 .B #include <unistd.h>
36 .BI "int brk(void *" addr );
37 .BI "void *sbrk(intptr_t " increment );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
50 || ((_XOPEN_SOURCE >= 500) &&
51 ! (_POSIX_C_SOURCE >= 200112L))
52 .\" (_XOPEN_SOURCE >= 500 ||
53 .\" _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
54 From glibc 2.12 to 2.19:
55 _BSD_SOURCE || _SVID_SOURCE
56 || ((_XOPEN_SOURCE >= 500) &&
57 ! (_POSIX_C_SOURCE >= 200112L))
58 .\" (_XOPEN_SOURCE >= 500 ||
59 .\" _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
61 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
62 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
68 change the location of the
70 which defines the end of the process's data segment
71 (i.e., the program break is the first location after the end of the
72 uninitialized data segment).
73 Increasing the program break has the effect of
74 allocating memory to the process;
75 decreasing the break deallocates memory.
78 sets the end of the data segment to the value specified by
80 when that value is reasonable, the system has enough memory,
81 and the process does not exceed its maximum data size (see
85 increments the program's data space by
92 of 0 can be used to find the current location of the program break.
97 On error, \-1 is returned, and
104 returns the previous program break.
105 (If the break was increased,
106 then this value is a pointer to the start of the newly allocated memory).
114 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
119 .\" are not defined in the C Standard and are deliberately excluded from the
120 .\" POSIX.1-1990 standard (see paragraphs B.1.1.1.3 and B.8.3.3).
128 memory allocation package is the
129 portable and comfortable way of allocating memory.
131 Various systems use various types for the argument of
133 Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP.
135 .\" \fIint\fP (e.g., XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
136 .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
137 .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
138 .\" \fIintptr_t\fP (e.g., XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6,
139 .\" Tru64 5.1, glibc2.2).
140 .SS C library/kernel differences
141 The return value described above for
143 is the behavior provided by the glibc wrapper function for the Linux
146 (On most other implementations, the return value from
148 is the same; this return value was also specified in SUSv2.)
150 the actual Linux system call returns the new program break on success.
151 On failure, the system call returns the current break.
152 The glibc wrapper function does some work
153 (i.e., checks whether the new break is less than
155 to provide the 0 and \-1 return values described above.
159 is implemented as a library function that uses the
161 system call, and does some internal bookkeeping so that it can
162 return the old break value.