To generate core dump on Linux we can add below parameters in initialize script which runs our executable. So whenever we initialize software or run our application and export environment variables we can copy the below lines to the script as well to dump core in case if we see any crash.
To set the location of core dumps you can set the core file path using the proc file system.
For example, if you want core dumps in
This will make sure your core file generation path remains intact for the processes you ran using the script.
mkdir -p /tmp/crash/corefiles
chmod 775 /tmp/crash/corefiles
echo "/tmp/crash/corefiles/%e.%s.core" > /proc/sys/kernel/core_pattern
Where variables are:
%e is the filename
%g is the gid the process was running under
%p is the pid of the process
%s is the signal that caused the dump
%t is the time the dump occurred
%u is the uid the process was running under
Also, you have to set the core file size, below command sets the core file size to unlimited
ulimit -c unlimited
Now to check the core file size set for each thread within a process we can check using
The output of above command:
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size unlimited unlimited bytes
Max open files 10000 10000 files
Max address space unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 31868 31868 processes
Max locked memory 65536 65536 bytes
Max file locks unlimited unlimited locks
Max pending signals 31868 31868 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
As we can see from the above output max core file size is set to unlimited.
In your case, you can follow the below steps.
- Create an initialize script which contains all environment exports as
well as the above core file generation related changes.
- From initializing script trigger your application.
- When there is a crash you should be able to see the core file as per
the core file location you have set.
- You can verify the core_pattern using:
cat /proc/sys/kernel/core_pattern and
see if your location is set correctly or not.