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 .\" SPDX-License-Identifier: GPL-2.0-or-later
7 .\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu>
8 .\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu>
10 .TH BRK 2 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
12 brk, sbrk \- change data segment size
15 .RI ( libc ", " \-lc )
18 .B #include <unistd.h>
20 .BI "int brk(void *" addr );
21 .BI "void *sbrk(intptr_t " increment );
25 Feature Test Macro Requirements for glibc (see
26 .BR feature_test_macros (7)):
34 || ((_XOPEN_SOURCE >= 500) &&
35 ! (_POSIX_C_SOURCE >= 200112L))
36 .\" (_XOPEN_SOURCE >= 500 ||
37 .\" _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
38 From glibc 2.12 to 2.19:
39 _BSD_SOURCE || _SVID_SOURCE
40 || ((_XOPEN_SOURCE >= 500) &&
41 ! (_POSIX_C_SOURCE >= 200112L))
42 .\" (_XOPEN_SOURCE >= 500 ||
43 .\" _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
45 _BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE >= 500
46 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
52 change the location of the
54 which defines the end of the process's data segment
55 (i.e., the program break is the first location after the end of the
56 uninitialized data segment).
57 Increasing the program break has the effect of
58 allocating memory to the process;
59 decreasing the break deallocates memory.
62 sets the end of the data segment to the value specified by
64 when that value is reasonable, the system has enough memory,
65 and the process does not exceed its maximum data size (see
69 increments the program's data space by
76 of 0 can be used to find the current location of the program break.
81 On error, \-1 is returned, and
88 returns the previous program break.
89 (If the break was increased,
90 then this value is a pointer to the start of the newly allocated memory).
98 4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
103 .\" are not defined in the C Standard and are deliberately excluded from the
104 .\" POSIX.1-1990 standard (see paragraphs B.1.1.1.3 and B.8.3.3).
112 memory allocation package is the
113 portable and comfortable way of allocating memory.
115 Various systems use various types for the argument of
117 Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP.
119 .\" \fIint\fP (e.g., XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
120 .\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
121 .\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
122 .\" \fIintptr_t\fP (e.g., XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6,
123 .\" Tru64 5.1, glibc2.2).
124 .SS C library/kernel differences
125 The return value described above for
127 is the behavior provided by the glibc wrapper function for the Linux
130 (On most other implementations, the return value from
132 is the same; this return value was also specified in SUSv2.)
134 the actual Linux system call returns the new program break on success.
135 On failure, the system call returns the current break.
136 The glibc wrapper function does some work
137 (i.e., checks whether the new break is less than
139 to provide the 0 and \-1 return values described above.
143 is implemented as a library function that uses the
145 system call, and does some internal bookkeeping so that it can
146 return the old break value.