Search code examples
csegmentation-faultbus-errorsigbus

Bus error vs Segmentation fault


Difference between a bus error and a segmentation fault? Can it happen that a program gives a seg fault and stops for the first time and for the second time it may give a bus error and exit ?


Solution

  • On most architectures I've used, the distinction is that:

    • a SEGV is caused when you access memory you're not meant to (e.g., outside of your address space).
    • a SIGBUS is caused due to alignment issues with the CPU (e.g., trying to read a long from an address which isn't a multiple of 4).