Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
06-15-2005, 01:06 AM
|
#1
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Rep:
|
Segmentation fault
hi to all
i have some problem with my code..when i compile my code its not giving me any error but when i run the application it gives the error "segmentation fault"...i checked the code and still i m not assigning a heavy memory to the code..but dont knw wht is the problem...
plz reply me abt the segmentation error..how to remove it from the code??or any tactics for that...its very urgent for me...
thanx for reading my thread and possibly then reply....
-Tejas
|
|
|
06-15-2005, 01:44 AM
|
#2
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
Hi,
your query was not very clear
Anyway if its a C code you are talking about do the following
Compile the code
Then in your terminal type
ulimit -c unlimited
Now run the executable and it will generate a core dump for the fault
Now since the core has got generated run a gdb on the core
This you can run by typing
gdb exe -c core
In gdb session type
bt
And this will give you the place of probable error.
Note: Compile your code with the -g option
Cheers
Z
|
|
|
06-15-2005, 01:54 AM
|
#3
|
LQ Newbie
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 7
Rep:
|
Re: Segmentation fault
Quote:
Originally posted by tejas15_10
hi to all
i have some problem with my code..when i compile my code its not giving me any error but when i run the application it gives the error "segmentation fault"...i checked the code and still i m not assigning a heavy memory to the code..but dont knw wht is the problem...
plz reply me abt the segmentation error..how to remove it from the code??or any tactics for that...its very urgent for me...
thanx for reading my thread and possibly then reply....
-Tejas
|
i just hate to see this term "segmentation error". I always get it when i run my c programs
possible errors
-----------------
1) you tried to use a pointer that was not allocated using malloc or calloc
2) you are trying to access a pointer that has been freed
3) you are trying to access an array element that does not exist
4) you use a fileopen function but it fails to open the file and then you try to write/read from the file thinking the open function was successful
these are a few but not all the causes. The best way is to use gdb and backtrace
|
|
|
06-15-2005, 07:37 AM
|
#4
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
i download the gdb but i dont knw how to compile code before that..i8 m newbie for linux..i compiled so many file and generated *.o file..my project contain 400+ files..so to compile it at the same time...wht is the syntax..code did not give the error at compile tile....but it gives an error at run time...and my code contain c and cpp files...and the size of an exe on Linux..size is 2.7MB+..in window..
reply me soon..i m waiting..
|
|
|
06-15-2005, 08:05 AM
|
#5
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
Your second posting is still more confusing than the first
First tell us what distribution of Linux u are using
And are you trying to compile GDB in linux or windows?
Cheers
Z
|
|
|
06-15-2005, 08:28 AM
|
#6
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
hi,
i m compile GDB in Linux...and i m using red Hat 9.0...
i collect so many data and articles regarding to segmentation fault but i coudnt find any one which is suite for my application....
i have to complete this thing befor 2 days..still i m not able to solve it..reply me soon..waiting for any solution....
if possible then give me basic steps also...
Thanx in advance
|
|
|
06-15-2005, 09:09 AM
|
#7
|
Member
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430
Rep:
|
Ok let me be clear
RedHat 9 CD had gdb rpm in it.
First check if your redhat has gdb installed in it
Type
rpm -q gdb
This will tell you if gdb is installed
If it has not been installed and if you have redhat CD
Loginto GUI
From the K Menu select Systemtools->AddRemovePackage
from it
Here select Development tools and click on update
It will ask you for the redhat CDs and Viola GDB is installed on your system
Cheers
Z
|
|
|
06-17-2005, 01:12 AM
|
#8
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
zulfilee,thanx for reply me..
i checked my code in one software which gives memory leak problem and i found some of memory leakage points...so how much probability for linux to handle this memory leak problem..in window this code is worked very weill..
I have GDB
And also give me command to run gdb and debug my code..
If any one having any idea regarding to my problem then reply me back
Best regards,Tejas
|
|
|
06-20-2005, 02:36 AM
|
#9
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
Hi to all
I solve the segmentation fault problem..but why it happen i dont knw.....Actually my application's folder level is like this:
R2Vector
||
========================
|| || || || ||
Image Jasper PDF GDFont Yahoo
i made make file for my application....now i give parameter to run my binary file..
yahoo folder contai all images on that i want to do something...
now when i give the input file path like "yahoo/yahoo.bmp" or "./yahoo/yahoo.bmp" it gives segmentation fault....
now if i put that file outside the yahoo..means in R2Vector folder then fault is remove..This is happening y that i want to knw...coz i coudnt put all file outside the yahoo....
Plz reply me back...
its very neede for me....
Thanks and Best regards
-Tejas
|
|
|
06-20-2005, 10:12 AM
|
#10
|
Member
Registered: Mar 2003
Location: Kansas City
Distribution: Debian unstable
Posts: 57
Rep:
|
You're probably going to actually have to understand what's happening to fix this and avoid similar mistakes. Somewhere in your program, you're accessing memory in an area that you're not supposed to, and that's when you get a segfault. Professional1983 already explained the mistakes that allow this to happen. If all you did was move a file to a different folder to fix it, it's not really fixed, it's just a latent bug. To really fix the bug, you have to find the point in the program where you're forgetting to allocate memory (or whatever the mistake is), which may not be anywhere near the point where it fails (memory management bugs are nasty). Or you could just use a language with automatic memory management.
I never really understood pointers, malloc, and free until I learned assembly language. Tools are nice, but they don't always replace real understanding.
|
|
|
All times are GMT -5. The time now is 02:34 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|