I understand that the program break is the highest virtual memory address that the Linux OS has allocated for a process, and therefore marks the highest address of the heap. You can get the address of the program break by calling sbrk( 0 ).
When I create the following trivial program, I get different results each time it's run:
#define _BSD_SOURCE
#include <stdio.h>
#include <unistd.h>
int main()
{
printf( "system break: %p\n", sbrk( 0 ) );
return 0;
}
For example, on my PC:
$ ./sbrk
system break: 0x81fc000
$ ./sbrk
system break: 0x9bce000
$ ./sbrk
system break: 0x97a6000
My understanding was that the heap is allocated immediately above the BSS section in virtual memory - I guess I was expecting that it would always have the same initial value for a trivial program like this. Is there some randomization or something in where the program break is initially positioned? If not, why is it different each time I run the program?