观察brk和mmap
cat /proc/$pid/maps
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
char* p0 = sbrk(0);
//*p0 = 65;
malloc(1);
char* p1 = sbrk(0);
printf("%d %p %p\n",p1-p0,p1,p0);
malloc(1);
char* p2 = sbrk(0);
printf("%d %p %p\n",p2-p0,p2,p0);
//*(p0+1024*136-1) = 65;
//*(p0+1024*136) = 65;
char* s = malloc(1024*256);
char* p3 = sbrk(0);
printf("%d %p %p %p\n",p3-p0,p3,p0,s);
// s[1024*260] = 65;
s[1024*260-16-1] = 65;
sleep(500);
//s[1024*1024-1] = 65;
//char* p4 = sbrk(0);
//printf("%d %p %p\n",p4-p0,p4,p0);
}
网友评论