'\"macro stdmacro
.if n .pH g2.brk @(#)brk	40.11 of 10/10/89
.\" Copyright 1989 AT&T
.nr X
.if \nX=0 .ds x} brk 2 "" "\&"
.if \nX=1 .ds x} brk 2 ""
.if \nX=2 .ds x} brk 2 "" "\&"
.if \nX=3 .ds x} brk "" "" "\&"
.TH \*(x}
.SH NAME
\f4brk\f1, \f4sbrk\f1 \- change data segment space allocation
.SH SYNOPSIS
\f4#include <unistd.h>\f1
.PP
\f4int brk(void \(**endds);\f1
.PP
\f4void \(**sbrk(int incr);\f1
.SH DESCRIPTION
\f4brk\fP
and
\f4sbrk\fP
are used to change dynamically the amount of space allocated
for the calling process's data segment [see
\f4exec\fP(2)].
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 end of the data segment.
The amount of allocated space increases as the break value increases.
Newly allocated space is set to zero.
If, however, the same memory space 
is reallocated to the same process
its contents are undefined.
.PP
\f4brk\fP
sets the break value to
.I endds\^
and changes the allocated space accordingly.
.PP
\f4sbrk\fP
adds 
.I incr\^
bytes to the break value and changes the allocated space accordingly.
.I incr\^
can be negative, in which case the amount of allocated space is decreased.
.PP
\f4brk\fP
and
\f4sbrk\fP
will fail without making any change in the allocated space if one or more of
the following are true:
.RS
.TP 13
\f4ENOMEM\fP
Such a change would result in more space being allocated
than is allowed by the system-imposed maximum process size [see
\f4ulimit\fP(2)].
.TP
\f4EAGAIN\fP
Total amount of system memory
available for a read during physical IO
is temporarily insufficient
[see \f4shmop\fP(2)].
This may occur even though the space requested was less than
the system-imposed maximum process size [see 
\f4ulimit\fP(2)].
.RE
.SH SEE ALSO
\f4exec\fP(2), \f4shmop\fP(2), \f4ulimit\fP(2), \f4end\fP(3C).
.SH DIAGNOSTICS
Upon successful completion,
\f4brk\fP
returns a value of 0 and
\f4sbrk\fP
returns the old break value.
Otherwise, a value of \-1 is returned and
\f4errno\fP
is set to indicate the error.
.\"	@(#)brk.2	6.2 of 9/6/83
.Ee
