BRK(2)
NAME
brk, sbrk − change data segment size
USAGE
caddr_t brk(addr) caddr_t addr;
caddr_t sbrk(incr) int incr;
DESCRIPTION
The system’s idea of the lowest data segment location not used by the program is called the break. Brk sets the break to addr (rounded up to the next multiple of the system’s page size). Locations greater than addr and below the stack pointer are not in the address space and will therefore cause a memory violation if the program attempts to access them.
In the alternate function sbrk, incr more bytes are added to the program’s data space and a pointer returns to the start of the new area.
When a program begins execution with an execve(2), the break is set at the highest location defined by the program and data storage areas. Consequently, programs that grow their data area are the principal clients of sbrk.
RETURN VALUE
A successful call to brk or sbrk returns zero and sets or extends the break. Otherwise, it returns -1 and sets errno as indicated below.
ERRORS
Sbrk will fail if one of the following is true:
[ENOMEM] The system’s memory limit was exceeded.
[ENOMEM] The maximum possible size of a data segment (compiled into the system) was exceeded.