Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ brk(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

end(S)

exec(S)

shmop(S)


 brk(S)                         6 January 1993                         brk(S)


 Name

    brk, sbrk - change data segment space allocation

 Syntax


    cc  . . .  -lc


    int brk (endds)
    char *endds;

    char *sbrk (incr)
    int incr;


 Description

    The brk and sbrk system calls are used to change dynamically the amount
    of space allocated for the calling process's data segment (see exec(S)).
    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.

    The brk system call sets the break value to endds and changes the allo-
    cated space accordingly.

    The sbrk system call adds incr bytes to the break value and changes the
    allocated space accordingly.  incr can be negative, in which case the
    amount of allocated space is decreased.

    The brk and sbrk system calls fail without making any change in the allo-
    cated space if one or more of the following is true:

    [EAGAIN]    Total amount of system memory available for a read during
                physical IO is temporarily insufficient (see shmop(S)).  This
                may occur even though the space requested was less than the
                system-imposed maximum process size.

    [ENOMEM]    Use of brk or sbrk would result in more space being allocated
                than is allowed by the system-imposed maximum process size.
                To be able to access more memory, use configure(ADM) to
                change the MAXUMEM system variable.


 Return value

    Upon successful completion brk returns a value of 0, and sbrk returns the
    old break value.  Otherwise, a value of -1 is returned and errno is set
    to indicate the error.

 See also

    end(S), exec(S), shmop(S)

 Standards conformance

    brk and sbrk conform to:
    AT&T SVID Issue 2 and Intel386 Binary Compatibility Specification, Edi-
    tion 2 (iBCSe2), but brk has been withdrawn from X/Open Portability
    Guide, Issue 3, 1989.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026