#include
#include
#include
#include
Int bss_end;
Int main (int argv, char * * arg c, char * * env)
{
Void * tret;
Char * pmem. Printf (" BSS end: % p \ n ", (char *) (& amp; Bss_end) + 4);
Tret=SBRK (0);
Printf (" % p \ n ", tret);
Tret=SBRK (0);
Printf (" % p \ n ", tret);
If (tret!=(void *) - 1)
{printf (" heap1 start: % p \ n ", tret);
}
If (BRK (tret (char *) - 1)==1)
{printf (" BRK error \ n ");
}
Tret=SBRK (0);
If (tret!=(void *) - 1)
{printf (" heap2 start: % p \ n ", tret);
} pmem=(char *) malloc (32).
If (pmem==NULL)
{perror (malloc "error"); The exit (EXIT_FAILURE);
}
Printf (" pmem: % p \ n ", pmem); Tret=SBRK (0);
If (tret!=(void *) - 1)
{printf (" heap1 end: % p \ n ", tret);
}
If (BRK (tret (char *) - 10)==1)
{printf (" BRK error \ n ");
}
Tret=SBRK (0);
If (tret!=(void *) - 1)
{printf (" heap2 end: % p \ n ", tret);
}
Printf (" % d \ n ", getpid ()); While (1); return 0;
}
Why first allocation page 21 4096 inside, SBRK (0) is at the end of the distribution page,


CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html