Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

shmop(2)

ulimit(2)

end(3)



  brk(2)                              CLIX                              brk(2)



  NAME

    brk, sbrk - Changes data segment space allocation

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    int brk(
      char *endds );

    char *sbrk(
      int incr );

  PARAMETERS

    endds   Specifies the new break value.

    incr    Specifies an amount to add to the current break value.

  DESCRIPTION

    The brk() and sbrk() functions are used to dynamically change the amount
    of space allocated for the calling process's data segment.  (See the
    exec() function.)  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 0.  However, if the same memory space is
    reallocated to the same process its contents are undefined.

    The brk() function sets the break value to endds and changes the allocated
    space accordingly.

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

  EXAMPLES

    1.  To set the break value to a fixed value:

        if (brk(new_break_value) != 0)
             perror("brk failed");


    2.  To increase the size of the process' data segment by 4096 bytes:

        if (sbrk(4096) == -1)



  2/94 - Intergraph Corporation                                              1






  brk(2)                              CLIX                              brk(2)



             perror("sbrk failed");


    3.  To determine the current break value:

        current_break_value = sbrk(0);
        if (current_break_value == -1)
             perror("sbrk failed");


  RETURN VALUES

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

  ERRORS

    The brk() and sbrk() functions will fail without making any change in the
    allocated space if one or more of the following are true:

    [ENOMEM]   The change would result in more space being allocated than is
               allowed by the system-imposed maximum process size.  (See
               ulimit().)

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

  RELATED INFORMATION

    Functions:  exec(2), shmop(2), ulimit(2), end(3)




















  2                                              Intergraph Corporation - 2/94




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