Bus error vs Segmentation fault

Thunderboltz picture Thunderboltz · May 8, 2009 · Viewed 30.5k times · Source

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 ?

Answer

paxdiablo picture paxdiablo · May 8, 2009

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).