Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sbrk(2) — UnixWare 2.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

end(3C)

exec(2)

malloc(3C)

shmop(2)

ulimit(2)






       brk(2)                                                        brk(2)


       NAME
             brk, sbrk - change data segment space allocation

       SYNOPSIS
             #include <unistd.h>
             int brk(void *endds);
             void *sbrk(int incr);

       DESCRIPTION
             brk and sbrk are used to change dynamically the amount of
             space allocated for the calling process's data segment [see
             exec(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 in-
             creases 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.

             brk sets the break value to endds and changes the allocated
             space accordingly.

             sbrk 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.

          Return Values
             On success, brk returns 0 and sbrk returns the old break
             value.  On failure, brk and sbrk return -1 and set errno to
             identify the error without making any change in the allocated
             space.

          Errors
             In the following conditions, brk and sbrk fail and set errno
             to:

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

             EAGAIN       Total amount of system memory or swap space
                          available is temporarily insufficient [see
                          shmop(2)].  This may occur even though the space
                          requested was less than the system-imposed
                          maximum process size [see ulimit(2)].



                           Copyright 1994 Novell, Inc.               Page 1













      brk(2)                                                        brk(2)


      REFERENCES
            end(3C), exec(2), malloc(3C), shmop(2), ulimit(2)

      NOTICES
         Usage
            Applications generally cope with the details of dynamic memory
            allocation/deallocation by using the malloc(3C) family of
            library functions.  Moreover, use of brk or sbrk can interfere
            with the dynamic memory used by malloc(3C).

         Considerations for Threads Programming
            Threads within a process share (by definition) the same
            address space; modifications to the address space by one
            thread can be perceived by sibling threads.

            The sbrk function is actually a front end to the brk system
            call and has a potential race condition that might produce
            incorrect results if used concurrently by sibling threads.
            Such usage is not advised.  The malloc(3C) family of functions
            has been made safe for use by threads.




























                          Copyright 1994 Novell, Inc.               Page 2








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