Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 447
Thunderboltz Avatar asked May 08 '09 06:05

Thunderboltz


1 Answers

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).
like image 187
paxdiablo Avatar answered Sep 19 '22 18:09

paxdiablo