Linux core file introduction

  

1. A brief introduction to the core file When a program crashes, it usually generates a core file in the specified directory. The core file is just a memory image (plus debugging information), mainly for debugging.

2. Turning on or off the generation of the core file Use the following command to prevent the system from generating a core file: ulimit -c 0 The following command can check if the option to generate the core file is open: ulimit -a This command will display all User customization, where option -a stands for “all”.

You can also modify the system file to adjust the core option. In /etc/profile, there is usually a sentence to prohibit the generation of core files. Usually this setting is reasonable: # No core files by defaultulimit -S -c 0 > /dev/null 2>&1 However, in the development process, sometimes in order to debug the problem, it is necessary to open the core file in a specific user environment to generate the settings in the user's ~/.bash_profile plus ulimit -c unlimited Let a specific user can generate a core file. If ulimit -c 0, it is also forbidden to generate a core file, and ulimit -c 1024 limits the size of the generated core file to no more than 1024kb.

3. Set Core Dump core turn The file directory and naming rules /proc/sys/kernel/core_uses_pid can be used to control whether the pid is added to the file name of the generated core file. If added, the file content is 1, otherwise 0/proc/sys/kernel/core_pattern can be Set the formatted core file save location or file name, for example, the original file content is core-%e can be modified like this: echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel /core_pattern The core file generated by the control will be stored in the /corefile directory. The generated file name is core-command name-pid-timestamp. The following is the parameter list: %p - insert pid into filename Add pid %u - insert current uid into Filename Add current uid %g - insert current gid into filename Add current gid %s - insert signal that caused the coredump into the filename Add the signal that causes the core %t - insert UNIX time that the coredump occurred into filename when adding the core file generation Unix time %h - insert hostname where the coredump happened into filename add hostname %e - insert coredumping executable name into filename add command name

4. Use the core file in the directory where the core file is located: gdb - c core will start the GNU debugger to debug the core file, and will display the name of the program that generated the core file, abort the signal of this program, etc. If you already know what program generated the core file, such as MyServer crashes Generate core.12345, then debug with this command: gdb -c core MyS How to do erver should learn the use of gdb

5. A small method to test the production of the core file directly into the command: kill -s SIGSEGV $$

6. Br>Why sometimes the program
Down
, but did not generate
Core
files.

Under Linux, there are settings that indicate resources available to the shell and to processes. You can see these settings using

#ulimit -a
. (ulimit is bash built-in Command)

-a All current limits are reported -c The maximum size of core files created -d The maximum size of a process
鈥檚
data segment -e The maximum scheduling priority ("nice") -f The maximum size of files written by the shell and its children -i The maximum number of pending signals -l The maximum size that may be Locked into memory -m The maximum resident set size (has no effect on Linux) -n The maximum number of open file descriptors (most systems do not allow this value to be set) -p The pipe size in 512-byte blocks (this May not be set) -q The maximum number of bytes in POSIX message queues -r The maximum real-time scheduling priority -s The maximum stack size -t The maximum amount of c Pu time in seconds -u The maximum number of processes available to a single user -v The maximum amount of virtual memory available to the shell -x The maximum number of file locks

If -c is displayed: core file size (blocks, -c)

If this value is 0, the core file cannot be generated. So you can use:

#ulimit -c 1024
or #ulimit -c unlimited
to enable the core file.

If a Core file is generated when a program error occurs, Segmentation fault (core dumped)
is displayed.

7. Core Dump
Core dump file directory and naming rules
:
/proc/sys/kernel/core_uses_pid can be controlled Whether to add pid as an extension to the file name of the core file, if added, the file content is 1, otherwise 0

Copyright © Windows knowledge All Rights Reserved