A segmentation fault (often shortened to segfault) is a particular error condition that can occur during the operation of computer software. In short, 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 (e.g., attempts to write to a read-only location, or to overwrite part of the operating system). Systems based on processors like the Motorola 68000 tend to refer to these events as Address or Bus errors.
Segmentation is one approach to memory management and protection in the operating system. It has been superseded by paging for most purposes, but much of the terminology of segmentation is still used, "segmentation fault" being an example. Some operating systems still have segmentation at some logical level although paging is used as the main memory management policy.
On Unix-like operating systems, a process that accesses invalid memory receives the SIGSEGV signal. On Microsoft Windows, a process that accesses invalid memory receives the STATUS_ACCESS_VIOLATION exception.
#include
Compiling and running it on NetBSD produces the following:
$ cc -g3 -o segfault segfault.c
$ ./segfault
Segmentation fault
Program received signal SIGSEGV, Segmentation fault.
0x080487b0 in main () at segfault.c:4
4 *p = 'x';
(gdb) bt
#0 0x080487b0 in main () at segfault.c:4
Note that the language standard does not say anything about what happens when a null pointer is dereferenced; it invokes undefined behaviour and literally anything might happen (including but not limited to exiting successfully). The conditions under which segmentation violations occur and how they manifest themselves is specific to an operating system.
Schutzverletzung | Access violation | Erreur de segmentation | Protectiefout | Naruszenie ochrony pamięci | Falha de segmentação
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Segmentation fault".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world