Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry, you are correct that I misinterpreted the addresses you cited.
There are no guarantees that the location of end is the program break point. If you read in more detail about end(3) you will see that it states that the program will break "somewhere near" &end and discusses that it may be at the start of the following page. It then goes on to cite that to find the current value of the program break, to use sbrk(). So what you can only really verify here is that end is within the range of the allocated memory for the program.
As suggested by you I have read about &end in the manual page .But here is something I would like to share :
1)If the program break will be somewhere near &end (perhaps at the start of the following page) why a such huge difference
btewwen sbrk(0) and &end ie.,0x2525000-0x601050.
2)More over as you suggested ,it is with in address space for a given program ,why multipple instances of same program is
giving different values of sbrk(0)
3)To the best of My knowledge ,memory of heap is allocated only at runtime and vm_area_struct instances for corresponding
heap segment is created at runtime only .
On what basis sbrk(0) is actually depend on .Nevertheless from man page it is sure that program break is not guaranteed
to be &end.
I am just curious about to know about point 1 & 2 .Please share why is this so,if you have any information .
Who says there are different values coming from sbrk? Compile and run it yourself. Why not read the references? I have no more detailed information to offer, the break point is not necessarily the value represented in the end variable.
Code:
#include <stdio.h>
#include <unistd.h>
void main(void)
{
printf("End of data segment1: %p\n", sbrk(0));
printf("End of data segment2: %p\n", sbrk(0));
printf("End of data segment3: %p\n", sbrk(0));
}
Output:
Code:
End of data segment1: 0x9435000
End of data segment2: 0x9435000
End of data segment3: 0x9435000
I mean multiple instances in sense not calling sbrk(0) in the same code , calling ./a.out multiple times .
Here is My sample code ,
#include<stdio.h>
#include<stdlib.h>
main()
{
printf("%p\n",sbrk(0));
}
output :
mgk@embeddedOS:~$ vi brk.c
mgk@embeddedOS:~$ gcc brk.c
brk.c: In function ‘main’:
brk.c:6:2: warning: format ‘%p’ expects argument of type ‘void *’, but argument 2 has type ‘int’ [-Wformat=]
printf("%p\n",sbrk(0));
^
mgk@embeddedOS:~$ ./a.out
0x2548000
mgk@embeddedOS:~$ ./a.out
0x21bb000
mgk@embeddedOS:~$ ./a.out
0xf16000
mgk@embeddedOS:~$ ./a.out
0xb8e000
mgk@embeddedOS:~$
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.