Tuesday, January 19, 2016

linux: how to activate and test kernel coredump property

[root@istanbul tmp]# sysctl -a | grep pattern
kernel.core_pattern = /tmp/core-%e-%s-%u-%g-%p-%t

test.c code:
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

int main(int argc, char **argv)
    int * nullpointer = NULL;
    printf("%d\n", *nullpointer);

    return 0;

# gcc -o testapp test.c

[root@istanbul tmp]# ./testapp
Segmentation fault
[root@istanbul tmp]# ls

no core file found.

[root@istanbul tmp]# ulimit -c

[root@istanbul tmp]# ls -alt /tmp/core-* | head -1
-rw------- 1 root root 241664 Jan 19 11:31 /tmp/core-testapp-11-0-0-2127-1453195860 

If you don't want to use testapp you can do it easily by using sleep command, too. 

sleep 10 &
killall -SIGSEGV sleep

No comments:

Post a Comment