A seldom-caused exception which you normally only see when Netscape traps SIGSEGV and reroutes it to a bus error to avoid a valid core from being dumped. It normally only happens when IPC fubars. I got a lot of real bus errors while programming some evil multithreaded code under IRIX.

In unix, a bus error results in your process receiving a SIGBUS signal. Bus errors are typically caused by attempts to access bad memory or attempts to access data that is not word aligned on architectures that require multibyte data to be word aligned.

Examples of "bad" memory might include areas that are reserved and therefore could never be valid, or areas of device mapped memory that is either nonexistant or currently in an error state.

On the Sun SPARC architecture, the following program generates a bus error due to a misaligned memory access.

main()
{

int *p = 1;

printf("%d\n",*p);
}

Note that if you change the 1 to a 0, you get a segmentation fault since page zero is not mapped. On Intel architectures and other architectures that allow non-word aligned memory access, both might generate a segment fault. On some architectures, page zero is mapped, and reads are allowed, so this may not generate any fault.

 

Bus error: Passengers dumped.

This is a rather silly story I found somewhere on the 'net, cannot again find for the life of me, and will hereby recite from memory with all due inaccuracy:

It was an icy winter evening as I walked home. Every now and then, my feet would hit a patch of frost on the sidewalk, and I would stumble before regaining my balance. Snow dusted lightly out of the starless night sky.

Most of the city streets were fairly empty, except for this one I happened to be walking alongside. On this street, traffic was backed up for quite a distance from some obstruction ahead. Walking onwards, I would soon find that the traffic was blocked by a bus, which had skidded across the road and hit a light post. The road was fairly slick with ice from a freezing rain earlier in the evening, and the driver had apparently not been gentle enough on the brakes to avoid skidding.

As I walked along the sidewalk, opposite the direction traffic would usually be going on the nearby road, I had just about passed the bus when its driver's side sliding window opened quickly, and an object was hurled out, nearly hitting me in the head! Surprised, I looked down to see what the object was. An apple core now lay in the frozen slush of the gutter.

It was just after that when I happened to glance up at the bus's dot matrix destination sign, which had apparently changed from its usual "42 Downtown" to a far more appropriate message:


 BUS ERROR
CORE DUMPED

Log in or register to write something here or to contact authors.