Linux core file settings

    When Linux program under unusual exit, the kernel is generated in the current working directory of a core file (a memory image, and add debugging information, you need to add at compile time -g -Wall). 
Use gdb to see the core file, you can cause the program to indicate where the error code file and line number.

And generating switch 1. core file size limit

1.1 ulimit -c command to view the generated switch core file.
If the result is 0, then this feature is disabled, does not generate core files.

1.2 ulimit -c filesize command, can limit the size of the core files (filesize units of kbyte).
If the generated information exceeds this size, it will be cut, and ultimately generate an incomplete or simply do not generate core files.
If the resulting file retrenched core, this core file debugging time, gdb will prompt an error.
Use the following command to indicate unlimited size core file.

$ ulimit -c unlimited

Use the following command to prevent the system generates a core file:

$ ulimit -c 0

Note: ulimit command after setting is only effective for a terminal, it is necessary to re-set after the other from the terminal.

 

2. Set Core Dump core file naming and directory

Filename 2.1 / proc / sys / kernel / core_uses_pid can control the generation of a core file is added with pid as the extension, file content is 1, represents pid added as the extension, the resulting core file format core.xxxx; is 0 representation generation of core files of the same name as the core.
Example:

$ echo "1" > /proc/sys/kernel/core_uses_pid

2.2 / proc / sys / kernel / core_pattern you can set the format of the core file location or file name

Example:

$ echo "/corefile/core-%e-%p-%t" > /proc/sys/kernel/core_pattern

Note: will control the resulting core file is saved to the next / corefile directory, file name is core- command name -pid- timestamp
The following is a list of parameters:
% the p-- INSERT INTO filename pid added pid
% U - INSERT current uid into filename add the current UID
% G - INSERT current GID INTO filename add the current GID
% S - INSERT signal that Caused the coredump INTO the filename is added resulting in core signal
% t - insert UNIX time that the coredump occurred into filename added core when the file generation time unix
% h - insert hostname where the coredump happened into filename added hostname
% e - insert coredumping executable name into filename Add command name

2.3 Precautions
2.3.1 directory proc file system is a pseudo file system, so as to provide an interface for the operating system to access the file system kernel data. / proc content directory is generated automatically when the system startup, some files can be changed, some of the files can not be changed.
For example, you can fine-tune the parameters by modifying the kernel proc file. Use vi may not be successfully edited proc / sys / kernel / core_pattern, can only use the echo command to change or modify sysctl command.
Sometimes the echo command has no effect, you must use the sysctl command
Example:

$ sysctl -w "kernel.core_pattern=/corefile/core_%e_%t" >/dev/null  
$ sysctl -w "kernel.core_uses_pid=0" >/dev/null

Note: For an explanation core storage directory, if you do not specify a directory, the syntax is as follows

$ sysctl -w "kernel.core_pattern=core-%e-%p-%t" >/dev/null

2.3.2 modify /etc/sysctl.conf (alternatives)
Add the need to preserve path "kernel.core_pattern = /tmp/corefile/core.%e.%t", to note that the path must have write access to application ,
otherwise the core file is not generated. And then execute the command "sysctl -p" to take effect.
About core_users_pid default sysctl file already exists in the inside, do not need to change, pid is very important information.

2.3.3 ensure that the Core Dump directory settings are pre-existing

 

Guess you like

Origin www.cnblogs.com/zhanggaofeng/p/11945972.html