Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Segmentation fault (core dumped) 1

Status
Not open for further replies.

netcomander

Programmer
Jul 20, 2001
68
DE
hi all,

meanwhile I think I'm more or less desperate.

my problem:

I program under linux (redhat 7.0) (gnu), and know
when I'm almost done with my sourcecode, this damned
segmentation fault appeared while I
run my program.

On wich stage my program is interrupted depends obviously
on where I put a simple printf("hallo"); into my code.
This is rather strange, atleast to me.

is there anybody out there who could give me a hint?

I really would be glad

greetings markus

 
Your problem is not in "Hello". You have memory corruption in some other place. In this case it is common when adding extra line to code lead to crash. Look for wild pointer or overwriting array boundary. Writing over boundary of stack array can lead to really nasty error witch difficult to debug, but some compiler can show you this during compilation.
Personally I use Purify to debug this kind of error.
 
Netcommander,

I have encountered this problem in multi-threaded code.

The relatively slow printf() slows down the calling thread. This exposes a race condition which does not occur in the non-printf code, due to fortunate (or unfortunate timing).

The other possibility is that printf() is being called from two threads at the same time and the version that you are using is not "thread-safe".

Brudnakm.
 
i agree with lim ,i would just add onething more

when you are trying to access memory without improperly
you get core dumped .its a way that the operating system
doesnot lets you get unauthorised access to a memory segment

you will get this with array,strings and anthing which
deals with internal pointers ,
see those parts where you are using ptr before and after
printf("hello"),this is a debugging technique
 
HELP ME PLEAE ! i've some problem about Segmentation fault.
My source code too long. how to know which line make Error.
 
Hello,
Segmentation fault is the error when you are trying to access a memory that does not really belong to you probably it got alloted to you because u used an uninitiallised pointer or during the course of a multithreaded program one of the thread tripped over the other because both of them were in the same uninitialised area, check your memory allocation if any. But if there has been no pointer or arrays part in your code then , it makes that code enough interesting to be see.....pls paste the code then.

Regards,
SwapSawe s-)
 
There is a good programm from Rational:
---Purify---
May be "good" is to strong word for Purify, but at least it designed to find such problems.
 
To know the line which is causing error, use GDB. it's availabe on After downloading and running gdb in the same dir. in which ur file exists,
u'll get a gdb prompt.
give the following commands:

gdb> file filename
gdb> run
gdb> backtrace

these series of commands shall show u the line nos. which is having faults even in the case of segmentation faults.
I hope this helps.

Regards
Nam
 
This can help to find place where program crush, but in case of memory corruption real place of error can be in absolutly other place.
And I know only "purify" that can show real place of corruption.
Does somebody know any other simular program?
 
There are bound to be other programs, but
Code:
purify
is quick and simple to use, and easy to include in your makefiles. However - I found that salespeople from
Code:
Rational
continually phoned me up after I downloaded an evaluation version - so be warned.

Also Purify can get caught out in some situations with memory leaks - it can miss
Code:
free
's (especially when an objects memory was
Code:
malloc
'd in a different function somewhere)

Still purfiy will show you the exact call (in however many nested functions) that made the error occur. Personally I usually found I had overwritten a fixed length field within a structure whenever I got them. :)

Loon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top