Interview Questions

What do Segmentation violation, `Bus error, and General protection fault mean? What is a core dump?

C Interview Questions and Answers


(Continued from previous question...)

What do Segmentation violation, `Bus error, and General protection fault mean? What is a core dump?

These symptoms (and any similar messages having to do with memory access violations or protection faults) generally mean that your program tried to access memory it shouldn't have, invariably as a result of stack corruption or improper pointer use. Likely causes are:
* overflow of local (``automatic,'' stack-allocated) arrays * inadvertent use of null pointers
* uninitialized, misaligned, or otherwise improperly allocated pointers
* stale aliases to memory that has been relocated
* corruption of the malloc arena
* attempts to modify read-only values (those declared const, and string literals
* mismatched function arguments, especially involving pointers; two possibilities are scanf and fprintf (make sure it receives its first FILE * argument)
Under Unix, any of these problems almost invariably leads to a ``core dump'': a file named core, created in the current directory, containing a memory image of the crashed process, for debugging.
The distinction between ``Bus error'' and ``Segmentation Violation'' may or may not be significant; different versions of Unix generate these signals under different sets of circumstances. Roughly speaking, a segmentation violation indicates an attempt to access memory which doesn't even exist, and a bus error indicates an attempt to access memory in an illegal way

(Continued on next question...)

Other Interview Questions