Where is the core file in Linux

Set 0X00 core file size

List the limits of all resources:ulimit -a

Or check the size of the core file:ulimit -c

core file size :
unlimited: unlimited core file size
0: The core file will not be generated if the program fails
1024: stands for 1024k, the core file cannot be generated beyond this size

Set the size of the core file:ulimit -c fileSize

Note:

Make this file size as large as possible.The core file size generated when the program crashes corresponds to the amount of memory the program occupies while it is running. If a stack overflow can occur, it takes up more disk space

0X01 Define the name and the file path of the core file

Default Build Path: Enter the same path where the executable file will run the command
Default generated name: The default name is core. The new core file overwrites the old core file

a. Set pid as the file extension

1: Add pid as an extension and the core file name is core.pid
0: Do not add a pid as an extension, the core file name is core
Change the content of the file / proc / sys / kernel / core_uses_pid to: 1
Command to change the file:echo “1”> / proc / sys / kernel / core_uses_pid
or
sysctl -w kernel.core_uses_pid = 1 kernel.core_uses_pid = 1

b. Control the location of the core file and the file name format

Modify the file:echo “/ corefile / core-% e-% p-% t”> / proc / sys / kernel / core_pattern
or:
sysctl -w kernel.core_pattern = / corefile / core-% e-% p-% t kernel.core_pattern = / corefile / core-% e-% p-% t
The core files can be generated uniformly in the / corefile directory, and the resulting file name is core-command name-pid-time stamp
Here is the parameter list:

Insert% p-pid in filename add pid (process ID)
% u Insert current UID in file name Add current UID (user ID)
Insert% g-current gid in filename Add current gid (usergroup ID)
% s insert signal that caused the core dump in the file name
Include% t UNIX time at which the core dump occurred in the file name
Include% h hostname where the core dump occurred in filename
Include% E-Insert-Name of the executable file in the file name

0X02 Test whether the core file can be generated
kill -s SIGSEGV $$
Verify that a core file is being generated in the / corefile directory

0X03 core debug file
Eg. test.c

[email protected]: ~ # gcc -o test test.c
[email protected]: ~ # ./test
Segmentation fault (core dumped)

bingo: A segfault has occurred and a core file has been generated
found core-test-31421-1476266571 in the / corefile directory
Start debugging
gdb ./test core-test-31421-1476266571

Display errors based on batch information

Linux generated core file, core file path settings