Core Dump & Segmentation Fault

Tag: unix Author: dazuicheng Date: 2009-09-20

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

have you googled?
I just wanna discuss the generic preventation approaches.

Best Answer

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.

Other Answer1

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.