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:

Please add your suggestions and debugging techniques in the comment below.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 13 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
13 comments… add one
  • Anthonus de Silva Apr 4, 2009 @ 16:50

    Suddenly my software started giving a Segmentation Fault.

    Language C, O/S: Linux.

    Following is a (pseudo) code snippet:

    1. x=strtok(y,”:”);
    2. if(strlen(x)>0) { do_something; }

    Line 2 would cause a Seg Fault. I would guess it should at least give me a false result.

    Hence I changed the code to:

    2. if(x != NULL) if(strlen(x) > 0) { do_something; }

    Note: you cant do if(x != NULL && strlen(x) > 0) as the strlen woud cause a SegFault (GP fault in Windows, i guess).


  • Felix Mwango Mutale Apr 14, 2009 @ 8:09

    Hello All Forum members,

    I am in dire need of help please. Can some one help me solve this segmentation problem ?

    I have part of the code like this. I have tried to put displays around to track down the flow as follows:

    LET GetInput = TRUE
    WHILE GetInput
    display ” Inside infield manno 1 ”
    display “GetInput = “, GetInput
    sleep 5
    INPUT w_manno,
    FROM manno,

    AFTER FIELD manno
    display ” Inside infield manno 2 ”
    sleep 5
    IF w_manno ” ”
    AND w_manno IS NOT NULL
    INTO w_cnt

    The second display is not coming. I can’t put a display just after the INPUT command or as I am getting a syntax error.

    I have also tried the following:

    LET GetInput = TRUE
    WHILE GetInput
    display ” Inside infield manno 1 ”
    display “GetInput = “, GetInput
    sleep 5
    INPUT BY NAME manno,

    But still I don’t seem to get what is going on. How do control the cursor to placed in the input field ?

    Thanking you in advance.

    Felix Mwango Mutale

  • Anup Jul 20, 2009 @ 13:15

    Segmentation Fault may also occur if disk is running out of free space!

  • Ruwinda Fernando Nov 15, 2009 @ 15:48

    Invoking “ps gave me “segmentation fault”. Managed to got rid-off the problem by upgrading “procps”.
    More info nixtaste

    Good Luck !!

  • mannex Nov 30, 2009 @ 18:54

    I’m having a strange behavior with an application, it segfaulted before every time while running it after the first error which happened after I closed it (after first use)
    But then I by accident missed the – while trying to run it in debugging mode. So it kinda looks like this “./nameapp d” and that puzzles me, any insight or guess what is going on there? What difference does that make?

    Cause after doing this it suddently worked again without error where as it segfaulted every single time before that. Could be random behaviour but others with the same problem seem to say it fixed it for them too.

  • satya Jan 2, 2010 @ 10:00

    hiii ……..my program works fine in turboc2 but it gives segmentation fualt in linux through putty………what should i do

  • Yuri Mar 30, 2010 @ 21:55

    9 out of 10:

    You screwed up your printf like statement: the number of your print format parameters is greater than the number of arguments you pass. Like this

    printf (” %d %s %s n”, string1, string2); Oops, you forgot to pass in your number which was supposed to be the first.

  • Narendra Mar 3, 2011 @ 7:37

    while make function i got following errors
    ./common/ptypes2tcl > gen/ptypes.cc
    /bin/sh: line 1: 15769 Segmentation fault ./common/ptypes2tcl > gen/ptypes.cc
    make: *** [gen/ptypes.cc] Error 139
    [root@localhost ns-2.33]#
    can you tell me how to solve this

    thanks in advance

  • sayali Mar 21, 2012 @ 8:16

    while doing make for ns-2.34
    ./common/ptypes2tcl > gen/ptypes.cc
    /bin/sh: line 1: 15769 Segmentation fault ./common/ptypes2tcl > gen/ptypes.cc
    make: *** [gen/ptypes.cc] Error 139
    [root@localhost ns-2.33]#
    can you tell me how to solve this…


  • wwo Mar 19, 2013 @ 10:21

    while doing make for ns-2.34
    ./common/ptypes2tcl > gen/ptypes.cc
    /bin/sh: line 1: 15769 Segmentation fault ./common/ptypes2tcl > gen/ptypes.cc
    make: *** [gen/ptypes.cc] Error 139
    [root@localhost ns-2.33]#
    can you tell me how to solve this…


  • sathyaraj May 28, 2013 @ 13:13

    Hi All,
    Today I have faced the segmentation fault in the Linux servers
    I have tried to remove the mod_nss rpm from the server once it started to ask the dependency library from the server I have removed the dependency library from the server once the depency library removed I was unable to run any of the command and getting the error as “segmentation fault”
    Once rebooted the server with the Linux iso I have upgraded the installation once it has been done the server comes to normal one

  • Gaurav Garg Jun 18, 2013 @ 7:12

    Hey i am getting this error >> Segmentation fault (core dumped)
    but this error comes at the time of runing the program not at the time of compilation.. all dependencies are installed so can you guide me how can fix it…?

  • jayesh Nov 2, 2015 @ 8:56

    when i run the command ” apt-get update” in kali linux 2.0 and it gives the error
    “Segmentation fault
    Reading package lists… Done ”

    how can i solve this error
    please tell me

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum