Step 1. Set ulimit unlimited in /etc/profile
ulimit -c unlimited > /dev/null 2>&1
Step 2. Set core unlimited in /etc/security/limits.conf
* soft core unlimited
Step 3. Set core pattern in /proc/sys/kernel/core_pattern
echo '/data/core/core.%e.%p.%t.%s.%u.%g' | sudo tee /proc/sys/kernel/core_pattern
mkdir -p /var/crash/user
Step 4. Set core pattern in /etc/sysctl.conf
kernel.core_pattern=/data/core/core.%e.%p.%t.%s.%u.%g
Step 5. Load new system control parameter to reflect changes
/sbin/sysctl -p
Step 6. Try below c code and it should generate core dump file in /data/core
> gcc core.c -o core
> ./core
Source code for core.c
/* core.c */
#include <stdio.h>
#include <malloc.h>
int main()
{
char *ptr;
ptr = malloc(sizeof(char)*10);
free(ptr);
int * crash = NULL;
*crash = 1;
// free would incur core dump
free(ptr);
}