2004-11-03 13:51:07 +00:00
|
|
|
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1993 Michael Haardt
|
|
|
|
.\" (michael@moria.de),
|
|
|
|
.\" Fri Apr 2 11:32:09 MET DST 1993
|
|
|
|
.\"
|
|
|
|
.\" This is free documentation; you can redistribute it and/or
|
|
|
|
.\" modify it under the terms of the GNU General Public License as
|
|
|
|
.\" published by the Free Software Foundation; either version 2 of
|
|
|
|
.\" the License, or (at your option) any later version.
|
|
|
|
.\"
|
|
|
|
.\" The GNU General Public License's references to "object code"
|
|
|
|
.\" and "executables" are to be interpreted as the output of any
|
|
|
|
.\" document formatting or typesetting system, including
|
|
|
|
.\" intermediate and printed output.
|
|
|
|
.\"
|
|
|
|
.\" This manual is distributed in the hope that it will be useful,
|
|
|
|
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
.\" GNU General Public License for more details.
|
|
|
|
.\"
|
|
|
|
.\" You should have received a copy of the GNU General Public
|
|
|
|
.\" License along with this manual; if not, write to the Free
|
|
|
|
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
|
|
|
|
.\" USA.
|
|
|
|
.\"
|
|
|
|
.\" Modified Wed Jul 21 19:52:58 1993 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\" Modified Sun Aug 21 17:40:38 1994 by Rik Faith <faith@cs.unc.edu>
|
|
|
|
.\"
|
_exit.2, brk.2, capget.2, chdir.2, chmod.2, chown.2, chroot.2, getdtablesize.2, gethostname.2, getpagesize.2, getsid.2, killpg.2, mknod.2, mknodat.2, poll.2, posix_fadvise.2, pread.2, readlink.2, setpgid.2, setreuid.2, sigaltstack.2, stat.2, symlink.2, sync.2, truncate.2, vfork.2, wait.2, wait4.2, a64l.3, abs.3, acos.3, acosh.3, asin.3, asinh.3, atan.3, atan2.3, atoi.3, cbrt.3, ceil.3, copysign.3, cosh.3, dirfd.3, div.3, ecvt.3, erf.3, erfc.3, exp.3, exp2.3, fabs.3, fdim.3, ffs.3, floor.3, fma.3, fmax.3, fmin.3, fmod.3, fpclassify.3, frexp.3, ftw.3, fwide.3, gcvt.3, getcwd.3, getdate.3, getgrent.3, gethostid.3, getpass.3, getpwent.3, getsubopt.3, getw.3, hypot.3, ilogb.3, index.3, isalpha.3, isgreater.3, iswblank.3, j0.3, ldexp.3, lockf.3, log.3, log10.3, log1p.3, logb.3, lrint.3, lround.3, mkstemp.3, mktemp.3, modf.3, mq_receive.3, mq_send.3, nan.3, nextafter.3, posix_fallocate.3, posix_memalign.3, printf.3, qecvt.3, random.3, realpath.3, remainder.3, remquo.3, rint.3, round.3, scalb.3, scalbln.3, scanf.3, siginterrupt.3, signbit.3, sigset.3, sinh.3, sqrt.3, strcasecmp.3, strcat.3, strchr.3, strcmp.3, strcoll.3, strcpy.3, strfry.3, strpbrk.3, strsep.3, strspn.3, strstr.3, strtod.3, strtok.3, strtol.3, strtoul.3, strxfrm.3, tanh.3, tgamma.3, trunc.3, ttyslot.3, ualarm.3, usleep.3, wprintf.3, armscii-8.7, cp1251.7, iso_8859-10.7, iso_8859-11.7, iso_8859-13.7, iso_8859-14.7, iso_8859-3.7, iso_8859-5.7, iso_8859-6.7, iso_8859-8.7, koi8-u.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 17:19:13 +00:00
|
|
|
.TH BRK 2 2010-09-20 "Linux" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
brk, sbrk \- change data segment size
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <unistd.h>
|
|
|
|
.sp
|
2008-06-12 04:47:47 +00:00
|
|
|
.BI "int brk(void *" addr );
|
2004-11-03 13:51:07 +00:00
|
|
|
.sp
|
|
|
|
.BI "void *sbrk(intptr_t " increment );
|
2007-07-08 12:11:40 +00:00
|
|
|
.sp
|
|
|
|
.in -4n
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
|
|
.BR feature_test_macros (7)):
|
|
|
|
.in
|
|
|
|
.sp
|
|
|
|
.BR brk (),
|
|
|
|
.BR sbrk ():
|
2010-09-17 15:22:01 +00:00
|
|
|
.ad l
|
|
|
|
.RS 4
|
|
|
|
.PD 0
|
|
|
|
.TP 4
|
|
|
|
Since glibc 2.12:
|
|
|
|
.nf
|
|
|
|
_BSD_SOURCE || _SVID_SOURCE ||
|
brk.2, chroot.2, faccessat.2, fchmodat.2, fchownat.2, fstatat.2, futimesat.2, getdtablesize.2, getpagesize.2, getsid.2, linkat.2, mkdirat.2, mknodat.2, openat.2, pread.2, readlinkat.2, renameat.2, setpgid.2, sigaltstack.2, symlinkat.2, sync.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, unlinkat.2, utimensat.2, vfork.2, acosh.3, asinh.3, atanh.3, dirfd.3, dprintf.3, ecvt.3, expm1.3, fexecve.3, fmemopen.3, gcvt.3, getcwd.3, gethostid.3, getpass.3, getsubopt.3, getw.3, mbsnrtowcs.3, mkfifoat.3, mkstemp.3, mktemp.3, opendir.3, posix_memalign.3, rint.3, siginterrupt.3, stpcpy.3, stpncpy.3, strdup.3, strerror.3, strnlen.3, strsignal.3, strtol.3, strtoul.3, ualarm.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcsdup.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 06:02:38 +00:00
|
|
|
(_XOPEN_SOURCE\ >=\ 500 ||
|
2010-09-17 15:22:01 +00:00
|
|
|
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
|
brk.2, chroot.2, faccessat.2, fchmodat.2, fchownat.2, fstatat.2, futimesat.2, getdtablesize.2, getpagesize.2, getsid.2, linkat.2, mkdirat.2, mknodat.2, openat.2, pread.2, readlinkat.2, renameat.2, setpgid.2, sigaltstack.2, symlinkat.2, sync.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, unlinkat.2, utimensat.2, vfork.2, acosh.3, asinh.3, atanh.3, dirfd.3, dprintf.3, ecvt.3, expm1.3, fexecve.3, fmemopen.3, gcvt.3, getcwd.3, gethostid.3, getpass.3, getsubopt.3, getw.3, mbsnrtowcs.3, mkfifoat.3, mkstemp.3, mktemp.3, opendir.3, posix_memalign.3, rint.3, siginterrupt.3, stpcpy.3, stpncpy.3, strdup.3, strerror.3, strnlen.3, strsignal.3, strtol.3, strtoul.3, ualarm.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcsdup.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 06:02:38 +00:00
|
|
|
!(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
|
2010-09-17 15:22:01 +00:00
|
|
|
.TP 4
|
|
|
|
.fi
|
|
|
|
Before glibc 2.12:
|
brk.2, chroot.2, faccessat.2, fchmodat.2, fchownat.2, fstatat.2, futimesat.2, getdtablesize.2, getpagesize.2, getsid.2, linkat.2, mkdirat.2, mknodat.2, openat.2, pread.2, readlinkat.2, renameat.2, setpgid.2, sigaltstack.2, symlinkat.2, sync.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, unlinkat.2, utimensat.2, vfork.2, acosh.3, asinh.3, atanh.3, dirfd.3, dprintf.3, ecvt.3, expm1.3, fexecve.3, fmemopen.3, gcvt.3, getcwd.3, gethostid.3, getpass.3, getsubopt.3, getw.3, mbsnrtowcs.3, mkfifoat.3, mkstemp.3, mktemp.3, opendir.3, posix_memalign.3, rint.3, siginterrupt.3, stpcpy.3, stpncpy.3, strdup.3, strerror.3, strnlen.3, strsignal.3, strtol.3, strtoul.3, ualarm.3, usleep.3, wcpcpy.3, wcpncpy.3, wcscasecmp.3, wcsdup.3, wcsncasecmp.3, wcsnlen.3, wcsnrtombs.3: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-09-19 06:02:38 +00:00
|
|
|
_BSD_SOURCE || _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
|
|
|
|
_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
|
2010-09-17 15:22:01 +00:00
|
|
|
.PD
|
|
|
|
.RE
|
2007-07-08 12:11:40 +00:00
|
|
|
.ad b
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH DESCRIPTION
|
2008-06-12 04:47:47 +00:00
|
|
|
.BR brk ()
|
|
|
|
and
|
|
|
|
.BR sbrk ()
|
|
|
|
change the location of the
|
|
|
|
.IR "program break" ,
|
|
|
|
which defines the end of the process's data segment
|
|
|
|
(i.e., the program break is the first location after the end of the
|
|
|
|
uninitialized data segment).
|
|
|
|
Increasing the program break has the effect of
|
|
|
|
allocating memory to the process;
|
|
|
|
decreasing the break deallocates memory.
|
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR brk ()
|
2004-11-03 13:51:07 +00:00
|
|
|
sets the end of the data segment to the value specified by
|
2008-06-12 04:47:47 +00:00
|
|
|
.IR addr ,
|
|
|
|
when that value is reasonable, the system has enough memory,
|
|
|
|
and the process does not exceed its maximum data size (see
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR setrlimit (2)).
|
|
|
|
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sbrk ()
|
2004-11-03 13:51:07 +00:00
|
|
|
increments the program's data space by
|
|
|
|
.I increment
|
|
|
|
bytes.
|
|
|
|
Calling
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sbrk ()
|
2008-06-12 04:47:47 +00:00
|
|
|
with an
|
|
|
|
.I increment
|
|
|
|
of 0 can be used to find the current location of the program break.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "RETURN VALUE"
|
|
|
|
On success,
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR brk ()
|
2006-11-25 04:13:11 +00:00
|
|
|
returns zero.
|
|
|
|
On error, \-1 is returned, and
|
|
|
|
.I errno
|
|
|
|
is set to
|
|
|
|
.BR ENOMEM .
|
2007-05-18 10:39:45 +00:00
|
|
|
(But see \fILinux Notes\fP below.)
|
2006-11-25 04:13:11 +00:00
|
|
|
|
|
|
|
On success,
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR sbrk ()
|
2008-06-12 04:47:47 +00:00
|
|
|
returns the previous program break.
|
|
|
|
(If the break was increased,
|
|
|
|
then this value is a pointer to the start of the newly allocated memory).
|
|
|
|
On error,
|
|
|
|
.I "(void\ *)\ \-1"
|
|
|
|
is returned, and
|
2004-11-03 13:51:07 +00:00
|
|
|
.I errno
|
|
|
|
is set to
|
|
|
|
.BR ENOMEM .
|
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:17 +00:00
|
|
|
4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
|
2008-06-12 04:47:47 +00:00
|
|
|
.\"
|
|
|
|
.\" .BR brk ()
|
|
|
|
.\" and
|
|
|
|
.\" .BR sbrk ()
|
|
|
|
.\" are not defined in the C Standard and are deliberately excluded from the
|
|
|
|
.\" POSIX.1-1990 standard (see paragraphs B.1.1.1.3 and B.8.3.3).
|
|
|
|
.SH NOTES
|
|
|
|
Avoid using
|
2005-10-28 13:40:41 +00:00
|
|
|
.BR brk ()
|
2007-04-12 22:42:49 +00:00
|
|
|
and
|
2008-06-12 04:47:47 +00:00
|
|
|
.BR sbrk ():
|
|
|
|
the
|
|
|
|
.BR malloc (3)
|
|
|
|
memory allocation package is the
|
|
|
|
portable and comfortable way of allocating memory.
|
|
|
|
|
2008-07-10 20:53:08 +00:00
|
|
|
Various systems use various types for the argument of
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR sbrk ().
|
2006-02-09 20:24:53 +00:00
|
|
|
Common are \fIint\fP, \fIssize_t\fP, \fIptrdiff_t\fP, \fIintptr_t\fP.
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" One sees
|
2007-06-08 11:56:22 +00:00
|
|
|
.\" \fIint\fP (e.g., XPGv4, DU 4.0, HP-UX 11, FreeBSD 4.0, OpenBSD 3.2),
|
2006-02-09 20:24:53 +00:00
|
|
|
.\" \fIssize_t\fP (OSF1 2.0, Irix 5.3, 6.5),
|
2007-05-16 04:00:06 +00:00
|
|
|
.\" \fIptrdiff_t\fP (libc4, libc5, ulibc, glibc 2.0, 2.1),
|
2007-06-08 11:56:22 +00:00
|
|
|
.\" \fIintptr_t\fP (e.g., XPGv5, AIX, SunOS 5.8, 5.9, FreeBSD 4.7, NetBSD 1.6,
|
2004-11-03 13:51:07 +00:00
|
|
|
.\" Tru64 5.1, glibc2.2).
|
2007-05-18 10:39:45 +00:00
|
|
|
.SS Linux Notes
|
2006-11-25 04:13:11 +00:00
|
|
|
The return value described above for
|
|
|
|
.BR brk ()
|
2007-06-08 09:56:56 +00:00
|
|
|
is the behavior provided by the glibc wrapper function for the Linux
|
2006-11-25 04:13:11 +00:00
|
|
|
.BR brk ()
|
2007-04-12 22:42:49 +00:00
|
|
|
system call.
|
|
|
|
(On most other implementations, the return value from
|
|
|
|
.BR brk ()
|
2008-06-12 04:47:47 +00:00
|
|
|
is the same; this return value was also specified in SUSv2.)
|
2007-04-12 22:42:49 +00:00
|
|
|
However,
|
2006-11-25 04:13:11 +00:00
|
|
|
the actual Linux system call returns the new program break on success.
|
2008-06-12 04:47:47 +00:00
|
|
|
On failure, the system call returns the current break.
|
|
|
|
The glibc wrapper function does some work
|
|
|
|
(i.e., checks whether the new break is less than
|
2008-09-29 09:00:36 +00:00
|
|
|
.IR addr )
|
2008-06-12 04:47:47 +00:00
|
|
|
to provide the 0 and \-1 return values described above.
|
2006-11-25 04:13:11 +00:00
|
|
|
|
2007-04-12 22:42:49 +00:00
|
|
|
On Linux,
|
2006-11-25 04:13:11 +00:00
|
|
|
.BR sbrk ()
|
|
|
|
is implemented as a library function that uses the
|
|
|
|
.BR brk ()
|
2007-04-12 22:42:49 +00:00
|
|
|
system call, and does some internal bookkeeping so that it can
|
2006-11-25 04:13:11 +00:00
|
|
|
return the old break value.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR execve (2),
|
|
|
|
.BR getrlimit (2),
|
2008-07-17 14:03:27 +00:00
|
|
|
.BR end (3),
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR malloc (3)
|