Unix & Linux: Running application ends with "Segmentation Fault" (2 Solutions!!)
Channel: Roel Van de Paar
Date: 2020-08-09

Unix & Linux: Running application ends with "Segmentation Fault"


The Question: I have a command line application that when run does not do what it is supposed
to do and at a certain point leaves the message:
Segmentation fault
What does this mean? What should I do?

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 70 people ==
A http://en.wikipedia.org/wiki/Segmentation_fault is the result of a memory
access violation. The program has referred to a memory address outside of what
was allocated to it, and the OS kernel responds by killing the program with
SIGSEGV.
This is a mistake, since there is no point in trying to access inaccessible
memory (it cannot be done). Mistakes of this sort are easy to make, however,
particularly in languages such as C and C++ (which account for a lot of common
applications). It indicates a bug in either the program itself or a library it
links to. If you wish to report the bug (do -- this helps), it is a good idea
to include a backtrace of the events that led up to the seg fault.
To do this, you can run the program inside gdb (the GNU debugger), which should
be available from any linux distro if it is not installed already (the package
will just be called "gdb"). If the broken application is called "brokenapp":
gdb brokenapp
A paragraph about copyright and licensing will appear, and at the end a prompt
with the cursor:
(gdb) _
Type run and hit enter. If you need to supply arguments (e.g. -x --foo=bar
whatever) append those (run -x --foo=bar whatever). The program will do what it
does, you will see the output and if you need to interact you can (note you can
run any sort of program, including a GUI one, inside gdb). At the point where
it usually segfaults you will see:
Program received signal SIGSEGV, Segmentation fault.
0x00000000006031c9 in ?? ()
(gdb) _
The second line of output here is just an example. Now type bt (for
"backtrace") and hit enter. You'll see something like this, although it may be
much longer:
(gdb) bt
#0 0x00000000006031c9 in ?? ()
#1 0x000000000040157f in mishap::what() const ()
#2 0x0000000000401377 in main ()
If it is longer, you'll only get a screenful at a time and there will be a --
More-- message. Keep hitting enter until it's done. You can now quit, the
output will remain in your terminal. Copy everything from Program received
signal SIGSEGV onward into a text file, and file a bug report with the
application's bug tracker; you can find these online by searching, e.g.
"brokenapp bug report" -- you will probably have to register so a reply can be
sent to you by email. Include your description of the problem, any arguments
you supplied to run, etc., and a copy of the backtrace (if it is very long,
there may be a means to attach a text file in the bug tracker interface). Also
include the version, if you know what it is (brokenapp --version may work, or
the man page may indicate how to get this), and which distribution you are
using.
Someone will hopefully get back to you in not too long. Filing bugs is a
usually appreciated.

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user terdon (https://unix.stackexchange.com/users/22222), user goldilocks (https://unix.stackexchange.com/users/25985), user gena2x (https://unix.stackexchange.com/users/68714), user Braiam (https://unix.stackexchange.com/users/41104), and the Stack Exchange Network (http://unix.stackexchange.com/questions/132192). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.