Using brk
()
and sbrk
()
A break is the greatest valid data address in the
process image that is not in the stack. When a program starts
executing, the break value is normally set by the
execve
()
function to the greatest address
defined by the program and its data storage.
Use the brk
()
function to set the break to a
greater address. You can also use the sbrk
()
function to add an increment of storage to the data segment of a
process. You can get the maximum possible size of the data segment by
a call to the getrlimit
()
function.
caddr_t brk(caddr_t addr); caddr_t sbrk(intptr_t incr);
brk
()
identifies the lowest data segment location
not used by the caller as addr. This location is rounded up to
the next multiple of the system page size.
sbrk
(), the alternate interface, adds
incr bytes to the caller data space and returns a pointer to
the start of the new data area.
For more information, see the
brk
(2),
sbrk
(2),
execve
(2), and
getrlimit
(2) man pages.