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, the break is set at the highest location defined by the program and data storage areas. Usually, therefore, only programs with growing data areas need to use sbrk.
RETURN VALUE
Zero is returned if the brk could be set; −1 if the program requests more memory than the system limit. Sbrk returns −1 if the break could not be set.
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.