LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 06-15-2005, 01:06 AM   #1
tejas15_10
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Rep: Reputation: 0
Exclamation 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
 
Old 06-15-2005, 01:44 AM   #2
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 06-15-2005, 01:54 AM   #3
professional1983
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 7

Rep: Reputation: 0
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
 
Old 06-15-2005, 07:37 AM   #4
tejas15_10
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
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..
 
Old 06-15-2005, 08:05 AM   #5
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 06-15-2005, 08:28 AM   #6
tejas15_10
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-15-2005, 09:09 AM   #7
zulfilee
Member
 
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
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
 
Old 06-17-2005, 01:12 AM   #8
tejas15_10
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-20-2005, 02:36 AM   #9
tejas15_10
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-20-2005, 10:12 AM   #10
rsheridan6
Member
 
Registered: Mar 2003
Location: Kansas City
Distribution: Debian unstable
Posts: 57

Rep: Reputation: 22
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.
 
  


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
what does Segmentation Fault mean ? baronlynx Linux - Newbie 10 10-25-2009 05:32 PM
yast segmentation fault, system freezing - nvidia driver at fault? BaltikaTroika SUSE / openSUSE 2 12-02-2005 10:34 AM
Help !!! Segmentation fault mola Linux - Software 3 06-23-2005 12:13 PM
Segmentation fault tejas15_10 Linux - Newbie 1 06-14-2005 05:44 AM
Segmentation fault santhosh_o Programming 3 10-26-2004 06:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:34 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
Open Source Consulting | Domain Registration