What does "Bus error" or "Segmentation fault" mean?


NOTE: If you are running someone else's program, the messages Bus error or Segmentation fault mean that there's a bug (error) in the program. If you're not interested in debugging the program yourself, you can skip the rest of this section. For Athena-supported software, you can report the bug by contacting a consultant through olc, or if you know the exact cause, by typing the following at the athena% prompt:
sendbug

If a program displays either of the above messages then the program was trying to access a memory location outside its address space. The computer detected this problem and sent a signal to your program, which caused it to abort.

Things that cause bus errors and segmentation violations are typically out-of-bounds array references and/or references through uninitialized or mangled pointers. Look very closely in your program for bizarre things like that. A common example is:

	int c;
	scanf("%d", c);
instead of the correct version:
	int c;
	scanf("%d", &c);
There are a number of methods for finding out where the program went out of bounds. One method is to use printf() statements to determine how far the program is getting before it crashes, and to print out the contents of interesting variables. A more sophisticated method is using dbx, a source level symbolic debugger. C programmers can also use codecenter, also known as saber. To learn about dbx or codecenter, you can read the manual pages by using the man command, as in:
man dbx
add saber; man codecenter
If you need to debug your program, you may want to enable a core dump. Usually, those two messages above would also have (core dumped) by them, indicating that the program wrote an image of its current memory into a file called core in that directory. Athena turned this off by default, since for most people core is just a waste of disk space.

If you want to turn it back on again, type quota -v and find out how many blocks (kilobytes) you have available in your quota. Then you can type:

limit coredumpsize 100
to limit your core dump size to 100K for your current login. Be very careful not to let yourself go over quota, as you would then not be able to create or edit files. You should delete the core file when you don't need it any more.

To allow core dumps and still not have quota worries, you can make a symbolic link from the name core into the /tmp directory. Core dumps created this way will not take up quota, and they will automatically vanish when you log out. The dump will also occur more quickly since it doesn't have to go over the network to your directory. To set up a core link in a directory:

ln -s /tmp/core.project ./core
unlimit coredumpsize
/tmp/core.project in the first line is the name that the core file is really called; the ln -s command creates a symbolic link from the filename core in the current directory, to a file named core.project in the /tmp directory.