Skip to content

(Linux) Generate dummy segmentation fault

Create a new C file.

#include <stdio.h>

int main()
{
    puts((void *)((unsigned long long)-1));
    return 0;

}

Compile and run.

[[email protected] log]# gcc -o seg seg.c
[[email protected] log]# ./seg
Segmentation fault
[[email protected] log]# tail /var/log/messages
Aug 26 23:39:18 slave kernel: seg[7788]: segfault at fffffffffffffff0 ip 00007fee2413c231 
sp 00007ffdb268c488 error 4 in libc-2.12.so[7fee240bb000+18a000]
[[email protected] log]#

It is very useful if you are working on custom monitoring to track segfault daemons/services/applications on your server.

Published inLinuxTutorials

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.