31

In Ubuntu I have faced the segmentation fault error many times. What is a segmentation fault and when does it occur?

1
  • 1
    Just to cover it up: I had a similar problem, whereas my segfaults were not reliably reproduceable and they came from (almost) random applications. Found out that most likely my memory is broken. So if quite any program causes segfaults, one might have a closer look at the RAM.
    – user140883
    Mar 16, 2013 at 23:21

3 Answers 3

29

An error saying segmentation fault (or segfault, or SIGSEGV) in Ubuntu and other Unix-like operating systems, or saying general protection fault in Windows, is when a program attempts to access a part of memory that cannot be accessed, or which the program is prohibited from accessing. A segmentation fault is a kind of program crash, that is, an abnormal termination of a program. See the Wikipedia articles on crashes, memory protection, segmentation fault, general protection fault, and SIGSEGV for more information (and a more textured understanding of the topic than is presented here).

A segmentation fault is almost always due to a bug in the program where it occurs. I am guessing most or all of your segmentation faults are happening from the same application. Please provide more details about the circumstances under which segmentation faults are happening on your machine, and what program is crashing. Please also provide the full and exact text of the error message you're receiving and any other messages that appear before it. This should make it possible for us to provide detailed advice specific to your problem (rather than just general information about what a segmentation fault is).

The best way for you to provide this information is for you to edit your question to include it. Alternatively, if you want this question to be just about segmentation faults in general, you could post a new question to ask about what specifically is causing your segmentation faults (if you do this, make sure to provide all these details in your new question).

9
  • fortunately all the segmentation fault are fixed by upgrading os :) . My question is about segmentation fault in general .Not for a particular app .
    – Tachyons
    May 17, 2012 at 14:16
  • @I'mnotthisperson I've edited my answer accordingly. (I'm retaining the directions for providing more information, for the benefit of other users experiencing segmentation faults, even though I know you don't need specific assistance with them right now.) May 17, 2012 at 14:18
  • Well this is about a segmentation fault in an app. I wanted to ask about it occurring in a C++ program where as the same program runs perfectly fine in Windows or Turbo C++(in wine)(i use anjuta in Linux).And well these are just basic programs and not applications(Programs like TREES,GRAPHS,etc)
    – Nirmik
    May 17, 2012 at 14:22
  • Thanks .But I am afraid in most of the cases asking question about segmentation fault in app is offtopic here. :)
    – Tachyons
    May 17, 2012 at 14:26
  • @Nirmik : probably it is the topic for stackoverflow :)
    – Tachyons
    May 17, 2012 at 14:28
4

Segmentation fault is caused by a bug in the application. Technically it means that application try to read or write to part of memory that doesn't belongs to it (or doesn't exist). It's of course forbidden to read or write to somebody else's memory and when system (kernel) detects this, it will force the application to quit.

0

Gone are the days when people used to trace through assembly code and debug a problem. Abends, Dr Watson, Segmentation fault. Those green days are gone.

One of the reasons for a segmentation fault is when code that has direct access to memory fails. When a piece of code tries to access the memory segment of a different application, segmentation fault occurs. Memory allocations are some times moved around to allow larger contiguous blocks of memory to get allocated. While it tries to recover, the kernel tries hard to save all its memory information to a file, current state of all applications running on the cpu and their state (last instruction run) to a file and just die. It will also try to store as much recovery information, and close as many files as it can, so that hdd's dont get broken links.

Debug it and fix it if you can reproduce it often. If you cannot reproduce it, just join your hands, kneel down and pray like hell that you don't see it "regularly".

6
  • Segfaults can be triggered in any program written in a language that allows direct memory access. They will not generally crash the kernel either.
    – Alex L.
    Jan 18, 2013 at 6:05
  • @AlexL. that is accurate. I'll edit my answer.
    – Siddharth
    Jan 18, 2013 at 8:07
  • I hope I have represented my thoughts correctly.
    – Siddharth
    Jan 18, 2013 at 8:10
  • @AlexL. Can you please review it one more time. I'll delete it, if its still not accurate.
    – Siddharth
    Feb 6, 2013 at 7:32
  • This is better. Still, (1) although possible it is extremely rare for a program to set the SIGSEGV handler to anything other than SIG_DFL (which is dump the core and exit for a SIGSEGV) since if you are accessing memory that you shouldn't be then something has gone very wrong and recovery is probably impossible. (2) A core will be dumped only once the process has been stopped. (3) The core dump only includes the memory and registers of the process that was dumped. (4) Other processes, the CPU and the kernal are not affected by a segfault of another process.
    – Alex L.
    Feb 6, 2013 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .