and are basic
memory management
Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory manag ...
system call
In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
s used in
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
and
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems to control the amount of memory allocated to the heap segment of the
process
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
* Business process, activities that produce a specific s ...
. These functions are typically called from a higher-level memory management library function such as . In the original Unix system, and were the only ways in which applications could acquire additional heap space; later versions allowed this to also be done using the call.
Description
The brk and sbrk calls
dynamically change the amount of space allocated for the heap segment of the calling process. The change is made by resetting the program break of the process, which determines the maximum space that can be allocated. The program break is the address of the first location beyond the current end of the data region. The amount of available space increases as the break value increases. The available space is initialized to a value of zero, unless the break is lowered and then increased, as it may reuse the same pages in some unspecified way. The break value can be automatically rounded up to a size appropriate for the
memory management
Memory management (also dynamic memory management, dynamic storage allocation, or dynamic memory allocation) is a form of Resource management (computing), resource management applied to computer memory. The essential requirement of memory manag ...
architecture.
and were considered legacy even by 1997 standards (
Single UNIX Specification
The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
v2 or POSIX.1-1998).
They were removed in POSIX.1-2001.
Function signatures and behavior
#include
int brk(void* end_data_segment);
void *sbrk(intptr_t increment);
is used to adjust the program break value by adding a possibly negative size, while is used to set the break value to the value of a pointer. Set parameter to zero to fetch the current value of the program break.
Upon successful completion, the subroutine returns a value of 0, and the subroutine returns the prior value of the program break (if the available space is increased then this prior value also points to the start of the new area). If either subroutine is unsuccessful, a value of is returned and the
global variable
In computer programming, a global variable is a variable with global scope, meaning that it is visible (hence accessible) throughout the program, unless shadowed. The set of all global variables is known as the ''global environment'' or ''global ...
is set to indicate the error.
[
Not every Unix-like system entertains the concept of having the user control the data segment. The ]Mac OS X
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
implementation of is an emulation and has a maximum allocation of 4 megabytes. On first call an area exactly this large is allocated to hold the simulated segment. When this limit is reached, −1 is returned and the is set to . always errors.
Error codes
The error is set and the allocated space remains unchanged if one or more of the following are true:
* The requested change allocates more space than is allowed by a system-imposed maximum.
* The requested change sets the break value to a value greater than or equal to the start address of any attached shared memory segment.
See also
* Exec (computing)
CMS EXEC, or EXEC, is an interpreted, command procedure control, computer scripting language used by the CMS EXEC Processor supplied with the IBM Virtual Machine/Conversational Monitor System (VM/CMS) operating system.
EXEC was written in 1966 by ...
*
References
{{Reflist
Memory management
Operating system APIs