Why Does The Segmentation Fault Occur on Linux / UNIX Systems?
According to wikipedia:
A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).
Usually signal #11 (SIGSEGV) set, which is defined in the header file signal.h file. The default action for a program upon receiving SIGSEGV is abnormal termination. This action will end the process, but may generate a core file (also known as core dump) to aid debugging, or perform some other platform-dependent action. A core dump is the recorded state of the working memory of a computer program at a specific time, generally when the program has terminated abnormally.
Segmentation fault can also occur under following circumstances:
a) A buggy program / command, which can be only fixed by applying patch.
b) It can also appear when you try to access an array beyond the end of an array under C programming.
c) Inside a chrooted jail this can occur when critical shared libs, config file or /dev/ entry missing.
d) Sometime hardware or faulty memory or driver can also create problem.
e) Maintain suggested environment for all computer equipment (overheating can also generate this problem).
Suggestions to debug Segmentation Fault errors
To debug this kind of error try one or all of the following techniques :
- Use gdb to track exact source of problem.
- Make sure correct hardware installed and configured.
- Always apply all patches and use updated system.
- Make sure all dependencies installed inside jail.
- Turn on core dumping for supported services such as Apache.
- Use strace which is a useful diagnostic, instructional, and debugging tool.
- Google and find out if there is a solution to problem.
- Fix your C program for logical errors such as pointer, null pointer, arrays and so on.
- Analyze core dump file generated by your system using gdb
Further readings:
- Read about the Segmentation fault in Wikipedia.
- Signal 11 while compiling the kernel.
- Example Debugging Session: Segmentation Fault Example
- Why does this not work!? How to find and fix faults in Linux applications.
- man pages gdb, core, signal
Please add your suggestions and debugging techniques in the comment below.
E-mail this to a Friend
Printable Version
You may also be interested in other helpful articles:
- Configure an Apache web server for core dump on segmentation faults
- Troubleshooting Lighttpd Chrooted RedHat PHP Version 5.1.6-20.el5_2.1
- Tell the truth to your user
- What you should (and shouldn’t) expect from 64-bit Linux?
- Howto: Building a Self-Healing Network with NAGIOS and Cfengine
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: abnormal termination, buggy program, dependencies, faulty memory, file signal, gcc segmentation fault, logical errors, memory location, null pointer, segmentation fault, strace, working memory



Recent Comments
Yesterday ~ 12 Comments
Yesterday ~ 8 Comments
Yesterday ~ 185 Comments
Yesterday ~ 15 Comments
Yesterday ~ 3 Comments