1BRK(2)                     Linux Programmer's Manual                    BRK(2)
2
3
4

NAME

6       brk, sbrk - change data segment size
7

SYNOPSIS

9       #include <unistd.h>
10
11       int brk(void *end_data_segment);
12
13       void *sbrk(intptr_t increment);
14

DESCRIPTION

16       brk()  sets  the  end  of  the  data  segment to the value specified by
17       end_data_segment, when that value is reasonable, the system  does  have
18       enough  memory  and  the process does not exceed its max data size (see
19       setrlimit(2)).
20
21       sbrk() increments the program's data space by increment bytes.   sbrk()
22       isn't  a  system  call, it is just a C library wrapper.  Calling sbrk()
23       with an increment of 0 can be used to find the current location of  the
24       program break.
25

RETURN VALUE

27       On success, brk() returns zero.  On error, -1 is returned, and errno is
28       set to ENOMEM.  (But see LINUX NOTES below.)
29
30       On success, sbrk() returns a pointer to the start of the new area.   On
31       error, -1 is returned, and errno is set to ENOMEM.
32

CONFORMING TO

34       4.3BSD; SUSv1, marked LEGACY in SUSv2, removed in POSIX.1-2001.
35
36       brk() and sbrk() are not defined in the C Standard and are deliberately
37       excluded from  the  POSIX.1  standard  (see  paragraphs  B.1.1.1.3  and
38       B.8.3.3).
39

NOTES

41       Various  systems use various types for the parameter of sbrk().  Common
42       are int, ssize_t, ptrdiff_t, intptr_t.
43

LINUX NOTES

45       The return value described above for brk() is the behaviour provided by
46       the  glibc  wrapper function for the Linux brk() system call.  (On most
47       other implementations, the return value from brk() is the same.)   How‐
48       ever,  the  actual  Linux  system call returns the new program break on
49       success.  On failure, the system call returns the current  break  (thus
50       for  example, the call brk(0) can be used to obtain the current break).
51       The glibc wrapper function does some work  to  provide  the  0  and  -1
52       return values described above.
53
54       On  Linux,  sbrk()  is  implemented as a library function that uses the
55       brk() system call, and does some internal bookkeeping so  that  it  can
56       return the old break value.
57

SEE ALSO

59       execve(2), getrlimit(2), malloc(3)
60
61
62
63Linux 2.4                         2003-11-01                            BRK(2)
Impressum