Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a segmentation fault on Linux?

In Linux:

What is a segmentation fault? I know it crashes programs, but is that some sort of memory leak problem, or something completely unrelated? Also, how do you deal with these? Is this typically a problem with the computer set-up, or within the application itself?

Also, does this happen in other OS's as well?

like image 729
Russel Avatar asked Jul 08 '10 03:07

Russel


1 Answers

A segmentation fault is when your program attempts to access memory it has either not been assigned by the operating system, or is otherwise not allowed to access.

"segmentation" is the concept of each process on your computer having its own distinct virtual address space. Thus, when Process A reads memory location 0x877, it reads information residing at a different physical location in RAM than when Process B reads its own 0x877.

All modern operating systems support and use segmentation, and so all can produce a segmentation fault.

To deal with a segmentation fault, fix the code causing it. It is generally indicative of poor programming, especially boundary-condition errors, incorrect pointer manipulation, or invalid assumptions about shared libraries. Sometimes segfaults, like any problem, may be caused by faulty hardware, but this is usually not the case.

like image 159
Borealid Avatar answered Oct 04 '22 13:10

Borealid