brk, sbrk
Purpose
Changes data segment space allocation.
Syntax
int brk (endds) char *sbrk (incr)
char *endds; int incr;
Description
The brk and sbrk system calls dynamically change the
amount of space allocated for the calling process's data
segment. (For information about data segments, see
"exec: execl, execv, execle, execve, execlp, execvp.")
The change is made by resetting the process's break value
and allocating the appropriate amount of space. The
break value is the address of the first location beyond
the current end of the data segment. The amount of allo-
cated space increases as the break value increases. The
newly allocated space is initialized to 0. The break
value can be automatically rounded up to a size appro-
priate for the memory management architecture.
The brk system call sets the break value to the value of
the endds parameter and changes the allocated space
accordingly.
The sbrk system call adds to the break value the number
of bytes contained in the incr parameter and changes the
allocated space accordingly. The incr parameter can be a
negative number, in which case the amount of allocated
space is decreased.
Return Value
Upon successful completion, the brk system call returns a
value of 0, and the sbrk system call returns the old
break value. If the brk or the sbrk system calls fail, a
value of -1 is returned and errno is set to indicate the
error.
Diagnostics
The brk and the sbrk system calls fail and the allocated
space remains unchanged if one or more of the following
are true:
ENOMEM The requested change will allocate more space
than is allowed by a system-imposed maximum.
(For information on the system-imposed maximum
on memory space, see "ulimit.")
ENOMEM The requested change will set the break value
to a value greater than or equal to the start
address of any attached shared memory segment.
(For information on shared memory operations,
see "shmat," "shmdt," and "shmget.")
Related Information
In this book: "exec: execl, execv, execle, execve,
execlp, execvp," "shmat," "shmdt," and "ulimit."