views:

209

answers:

2

Guys,

I want to know the exact difference between segmentation fault and core dump. I agree that these are operating system dependent and, of course, arise due to the memory mismanagement. But please come up with some generic approaches which needs to be followed to prevent these?

Sachin Chourasiya

+1  A: 

A core file is a memory image of a crashed process. With a debugger you can find out the possible causes of the crash. If you don't know what to do with a core file (except rm core), you can request not to generate them with limit coredumpsize 0.

A segmentation fault is one of the manifestations of a process crash. Usually it arises when the program tries to access memory that it shouldn't.

There are amny causes of segmentation fault. here is a non-exhaustive list:

  • access to data through an uninitialized pointer
  • access to malloc'ed memory which has been free'd
  • access to array elements beyond the array size
  • ...

Tools exist for detecting such memory bad access. purify or lint are example of these.

mouviciel
+1  A: 

A segmentation fault are the result of invalid memory access and cause a SIGINT signal that usually causes the application to terminate.

A core dump is a file that is usually written when an application crashes after e.g. a segmentation fault to that the developer can analyze the state of the application at the time of the crash.

dmeister