In Linux, enable the core dump configuration and use the shortest program to throw the core

Source: Internet
Author: User
What is core dump?

Core dump is also called core dump. When an exception occurs during the program running and the program exits abnormally, the operating system stores the current memory status of the program in a core file, which is called core dump. Core dump is helpful for problem diagnosis after the application crash is applied. Core dump is disabled by default during installation.

How to check whether core dump is enabled

Use ulimit-C to check whether the core dump is enabled. If the result is 0, this function is disabled and core files are not generated.

How to enable core dump

Method 1: run the command line interface (ulimit-C 1024). In this example, the core dump is opened and the file size is limited to 1024 kb. The current programs occupy fierce memory, the previous era of Writing C Programs to calculate memory has passed. If no restrictions are imposed, a core file may be used, and several GB will be used out ~, Of course, there are still no restrictions on the way [ulimit-C unlimited]

Method 2: configure the profile file and open the/etc/profile file. You can find [ulimit-s-c 0>/dev/null 2> & 1] in the file ], change it to [ulimit-s-c unlimited>/dev/null 2> & 1]
Method 3: Modify/etc/security/limits. in the conf file, add * Soft Core 0. This method can be used to open core dump [user Soft Core 0 or @ group Soft Core 0] for a specified user or user group ]. However, to use this method, you must comment out the line mentioned in method 2, which cannot exist at the same time.

How to view the core file storage path and file name format

By default, if the application crashes after the core is enabled, a core is generated at the application location. if the PID is used, the file name is not readable and cannot be managed.
View the path and format of the core file in use [More/proc/sys/kernel/core_pattern]
The PID configuration is automatically added in [More/proc/sys/kernel/core_uses_pid]. If it is set to 1, it is automatically added.

How to modify the storage path and file name format of core files

Modify/etc/sysctl. CONF file [vi/etc/sysctl. conf to add the path [kernel. core_pattern =/tmp/corefile/core. % E. % T. Note that the application must have the write permission on the path. Otherwise, the core file will not be generated. Then run the "sysctl-P" command to take effect. The core_users_pid already exists in the sysctl file by default and does not need to be changed. PID is still very important.

A list of formats supported by core files is attached:
% P-insert PID into filename [pid]
% U-insert current uid into filename [uid]
% G-insert current GID into filename [GID]
% S-insert signal that caused the coredump into the filename [core signal]
% T-insert UNIX time that the coredump occurred into filename [UNIX time when the core file is generated]
% H-insert hostname where the coredump happened into filename [host name]
% E-insert coredumping executable name into filename [Application name]

How to use the core generated by the test program

#include <iostream>using namespace std;int main() {    *(char *)1=1;    return 0;}  

 

SELF: http://blog.csdn.net/shijun_zhang/article/details/6577604 #

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.