Core Dump & Segmentation Fault

unix

Solution

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.

Problem

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

Original source