brk

Why does calling sbrk(0) twice give a different value?

谁说胖子不能爱 提交于 2019-11-28 00:55:22
I'm trying to understand the sbrk() function. From what I know: sbrk(0) returns the current address of the break and doesn't increment it. sbrk(size) increments the address of the break by size bytes and returns the previous address of the break. So I created something to test it: #include <unistd.h> #include <stdio.h> int main(void) { printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(5) = %p\n", sbrk(5)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x + 5 } So I'm expecting

How are sbrk/brk implemented in Linux?

守給你的承諾、 提交于 2019-11-27 00:37:51
问题 I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? 回答1: In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" ( struct vm_area_struct ). There is also a structure which represents (again in a very high level

Why does calling sbrk(0) twice give a different value?

ぐ巨炮叔叔 提交于 2019-11-26 23:27:35
问题 I'm trying to understand the sbrk() function. From what I know: sbrk(0) returns the current address of the break and doesn't increment it. sbrk(size) increments the address of the break by size bytes and returns the previous address of the break. So I created something to test it: #include <unistd.h> #include <stdio.h> int main(void) { printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(5) = %p\n", sbrk(5)); //

What does the brk() system call do?

假如想象 提交于 2019-11-26 16:51:00
According to Linux programmers manual: brk() and sbrk() change the location of the program break, which defines the end of the process's data segment. What does the data segment mean over here? Is it just the data segment or data, BSS, and heap combined? According to wiki: Sometimes the data, BSS, and heap areas are collectively referred to as the "data segment". I see no reason for changing the size of just the data segment. If it is data, BSS and heap collectively then it makes sense as heap will get more space. Which brings me to my second question. In all the articles I read so far, author

What does the brk() system call do?

大城市里の小女人 提交于 2019-11-26 04:56:55
问题 According to Linux programmers manual: brk() and sbrk() change the location of the program break, which defines the end of the process\'s data segment. What does the data segment mean over here? Is it just the data segment or data, BSS, and heap combined? According to wiki: Sometimes the data, BSS, and heap areas are collectively referred to as the \"data segment\". I see no reason for changing the size of just the data segment. If it is data, BSS and heap collectively then it makes sense as