99 lines
2.5 KiB
Groff
99 lines
2.5 KiB
Groff
'\"macro stdmacro
|
|
.if n .pH g2.brk @(#)brk 40.12 of 1/3/91
|
|
.\" Copyright 1991 UNIX System Laboratories, Inc.
|
|
.\" Copyright 1989, 1990 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
|
|
brk, sbrk \- change data segment space allocation
|
|
.Op c p a
|
|
.SH C SYNOPSIS
|
|
.B "#include <unistd.h>"
|
|
.sp
|
|
.B "int brk (void \(**endds);"
|
|
.sp
|
|
.B "void \(**sbrk (ssize_t incr);"
|
|
.Op
|
|
.Op f
|
|
.SH FORTRAN SYNOPSIS
|
|
.B "integer *4 function brk (endds)"
|
|
.br
|
|
.B "character * (*) endds"
|
|
.PP
|
|
.br
|
|
.B "character * 4096 function sbrk (incr)"
|
|
.br
|
|
.B "integer *4 incr"
|
|
.Op
|
|
.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 CAVEATS
|
|
\f4sbrk\f1(2) is not multithreaded. Simultaneous \f4sbrk\f1 calls with
|
|
positive increments will return the same value. It is recommended that
|
|
\f4malloc(2)\f1 be used instead of \f4sbrk(2)\f1.
|
|
.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
|