A tiny Segmentation fault study example (Page Fault).
This tiny code will produce a SIGSEGV (Segmentation fault) after compiling and executing
Create file example.c and fill it with this code:
1 2 3 4 5 6 7 8 9 10 11 | #include <stdio.h> int main() { char* text = "hello world"; text = 13423; printf(text); } </stdio.h> |
Compile:
1 | gcc -o example example.c |
Run and get a Segmentation fault:
1 | ./example |
Debug Segmentation fault:
1 | strace ./example |
Leave a Reply