Linux Core Dump Open tutorial

Source: Internet
Author: User

One, what is Coredump

We often hear that the program core dropped, need to locate the solution, the majority of this refers to the corresponding program due to a variety of anomalies or bugs caused in the operation of the abnormal exit or stop, and under certain conditions (why the need to meet certain conditions?) The following analysis will produce a file called core.

Under normal circumstances, the core file will contain the program runtime memory, register state, stack pointer, memory management information and a variety of function call stack information, etc., we can understand that the program is the current state store to generate the first file, many of the program error will produce a core file, Through the tool analysis of this file, we can locate the program exception exit when the corresponding stack call and other information, find out where the problem and solve in a timely manner.

Second, cored dump open

Perform a ulimit–c check to see if core dump is turned on, and if the result is 0, the core dump will need to be turned on without the generation of the core file being enabled. There are three ways to open the core dump, one for temporary activation and two for permanent activation.

Temporarily enable

Method 1 (Ulimit command method)

Execute the following command:

Ulimit-c 1024
Or
Ulimit-c Unlimited
In the previous example, the first one is to limit core dump file size of not more than 1024K, the latter is not limited the size of core dump files, the current program memory is more ferocious, the previous write C program needs to calculate the memory of the era has passed. If there is no limit, maybe a core file, a few g went out. So it's best to limit the small.

Two methods that are permanently enabled:

Method Two (Profile file modification method)

Open the/etc/profile file, add the following and make it effective:

Ulimit-s-C Unlimited >/dev/null 2>&1
Note: If the file has a ulimit-s-C 0 >/dev/null 2>&1 line, the line needs to be commented out first. After the setup is complete, it takes effect through the execution source/etc/profile.

Method Three (modify/etc/security/limits.conf file)

Locate the "* Soft core 0" line and modify it to read as follows:

The code is as follows Copy Code
User Soft Core 1024
or @group soft core 1024

This method can open core dump for a specified user or user group, such as "* Soft core 10485760", i.e. the core dump file size is 10G.

Note that the settings in this and method two are conflicting, and you can set them in one place, which is recommended as a third method, because it is more flexible to set up for different users and groups.

Note: The above three method settings do not need to restart the machine, what needs to be done is to exit the terminal and reconnect, restart the need for core dump program.

Iii. Modifying the core dump file format

Customize the core path, name format, by modifying the following two configurations:

The code is as follows Copy Code

Echo 1 >/proc/sys/kernel/core_uses_pid
echo '/corefiles/core-%e-%p-%t ' >/proc/sys/kernel/core_pattern
Here we go. Configuration instructions for the last parameter:

Percent% single% character
%p The process ID of the dump process
The actual user ID of the dump process in%u
%g The actual group ID of the dump process
%s is causing this core dump signal
%t Core Dump time (number of seconds from January 1, 1970)
%H Host Name
%e program file name

Again, the first sentence configuration,/proc/sys/kernel/core_uses_pid if the content of this file is configured to 1, then even if%p is not set in Core_pattern, the resulting core dump filename will still be added to the process ID.

It should be noted that since the configuration under/proc is immediately effective, the previous configuration will be invalidated after reboot. So you can add the following configuration to the/etc/sysctl.conf file, as follows:

The code is as follows Copy Code
Kernel.core_uses_pid = 1
Kernel.core_pattern =/corefiles/core-%e-%p-%t

After saving, the execution sysctl-p takes effect.

Note: Note that the above configured corefiles must have write access to the directory, or the core dump file cannot be generated, and can be created using the following command:

  code is as follows copy code

# mkdir/ Corefiles
# chmod 777/corefiles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.