brk(), sbrk() - set or change space allocation
#include <unistd.h>
int brk (void *addr)
void * sbrk (int incr)
The brk(3) and sbrk(3) functions change the amount of space allocated for the calling process. They change the space by resetting the break value for the process; as the break value increases, so does the allocated space. Initially, a newly-allocated space is set to 0.
The brk(3) function sets the break value to addr and sets the allocated space accordingly.
The sbrk(3) function increases the break value by incr bytes, and adjusts the allocated space. If incr, the function decreases the break value by the appropriate amount. if the value of incr is 0, then the function returns the current value of the break point.
The interaction of brk(3) and sbrk(3) with other memory functions is uncertain. Be careful, since other function calls may be call functions such as free(3) or mmap(2) in a non-obvious way.
The brk(3) and sbrk(3) functions are often used as atomic units to build other memory allocation functions. Application programmers should consider whether mmap(2) could be used, because it is more portable with other memory allocation functions.
The brk(3) call returns 0 if it completes successfully. Otherwise it returns -1 and sets errno to indicate the error.
The brk(3) and sbrk(3) functions can fail for the following reasons:
exec(2)
mmap(2)
malloc(3)