LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 10-08-2015, 01:00 AM   #16
gopikrishna mogasati
LQ Newbie
 
Registered: Jun 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
program break issue with brk system call


Hi berndbausch ,

I am sorry for my wrong interpretation .
 
Old 10-08-2015, 07:58 AM   #17
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 6,620
Blog Entries: 12

Rep: Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298
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.
 
Old 10-08-2015, 09:04 AM   #18
gopikrishna mogasati
LQ Newbie
 
Registered: Jun 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
program break issue with brk system cal

Hi rtmistler ,

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
 
Old 10-08-2015, 09:17 AM   #19
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 6,620
Blog Entries: 12

Rep: Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298
Maybe you should read some of these references:

http://duartes.org/gustavo/blog/post...ram-in-memory/
https://www.ualberta.ca/CNS/RESEARCH...sters/mem.html
http://www.cyberciti.biz/faq/linux-v...space-command/
 
Old 10-08-2015, 09:21 AM   #20
gopikrishna mogasati
LQ Newbie
 
Registered: Jun 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thumbs up program break issue with brk system call

Hi rtmistler ,

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 .
 
Old 10-08-2015, 09:28 AM   #21
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 6,620
Blog Entries: 12

Rep: Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298Reputation: 2298
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
 
Old 10-08-2015, 09:41 AM   #22
gopikrishna mogasati
LQ Newbie
 
Registered: Jun 2014
Posts: 12

Original Poster
Rep: Reputation: Disabled
program break issue with brk system call

Hi rtmistler ,

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:~$
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use system call sys_sync(() in a c program and why is it used? chaiein Linux - Software 2 07-22-2013 09:38 AM
Netbeans 7.3: Program does not break at break points when debugging JavaScript OtagoHarbour Programming 0 02-22-2013 02:44 AM
issue system call from running fortran program msander Linux - Newbie 1 04-24-2009 07:49 AM
How to issue system call from running fortran program swerdna Programming 3 12-27-2006 07:44 AM
Retain Server Connection Up, If Client Break, write system call return SIGPIPE anandss2004 Programming 2 10-24-2005 12:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration