Introduction to Linux Core files

Source: Internet
Author: User
Tags naming convention

Introduction to Linux Core files

Http://www.cnblogs.com/dongzhiquan/archive/2012/01/20/2328355.html

1. A brief introduction to the core file
When a program crashes, it typically generates a core file in the specified directory. The core file is simply a memory image (plus debugging information), which is used primarily for debugging purposes.

2. Turn core file generation on or off
Use the following command to prevent the system from generating a core file:
Ulimit-c 0
The following command checks to see if the option to generate a core file is open:
Ulimit-a
This command will show all user customizations, where option-a stands for "all".

You can also modify the system files to adjust the core options
In/etc/profile there is usually a sentence to prohibit the creation of a core file, which is usually justified:
# No core Files by default
Ulimit-s-C 0 >/dev/null 2>&1
However, in the development process sometimes in order to debug the problem, or need to open the core file in a specific user environment generated by the settings
Add Ulimit-c Unlimited to the user's ~/.bash_profile to allow a specific user to produce a core file
If Ulimit-c 0 is also forbidden to produce core files, ulimit-c 1024 limits the resulting core file size to not exceed 1024kb

3. Set the core dump file directory and the naming convention of the kernel dump
/proc/sys/kernel/core_uses_pid to control whether the resulting core file has a PID extension in the filename, If you add the file content is 1, otherwise 0
/proc/sys/kernel/core_pattern can set the format of the core file save location or file name, such as the original file content is core-%e
can be modified:
echo "/ Corefile/core-%e-%p-%t ">/proc/sys/kernel/core_pattern
will control the resulting core file will be stored in the/corefile directory, The resulting file name is core-command name-pid-timestamp
The following is a list of parameters:
   %p-insert pid into filename add pid
   %u -Insert current UID into filename to add present UID
   %g-insert current GID into filename to add present GID
 &N bsp; %s-insert signal that caused the coredump into the filename adds a signal that leads to core generation
   %t-insert U NIX time that the coredump occurred to filename add a core file when you build Unix times
   %h-insert hostname where the Coredump happened into filename add host name
   %e-insert coredumping executable name into filename add command name

4. Using the core file
In the directory where the core file is located, type:
Gdb-c Core
It will start the GNU debugger to debug the core file, and will show the name of the program that generated the core file, the signal to abort the program, and so on.
If you already know what program generated this core file, such as MyServer crashes generating core.12345, debug with this command:
Gdb-c Core MyServer
Here's how to learn the use of GDB

5. A small way to test the resulting core file
Direct Input Command:
Kill-s SIGSEGV $$

6. sometimes The program is down, but the Core file is not generated .

Under Linux, there are some settings that indicate the resources available to the shell and to processes. can use

#ulimit -A to see these settings. (Ulimit is bash built-in Command)

-A All current limits is reported
-c The maximum size of core files created
-d The maximum size of a process
Echnical'sData 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 the May is locked into memory
-M The maximum resident set size (have no effect on Linux)
-N The maximum number of open file descriptors (most systems does not allow this value to be set)
-P The pipe size in 512-byte blocks
-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 CPU 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

As can be seen here, 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 or #ulimit-C Unlimited to enable the core file.

If the program generates a core file when an error occurs, segmentation fault (core dumped)is displayed.

7. Core dump file directory and naming rules :
/proc/sys/kernel/core_uses_pid can control whether a PID is added to the file name of the resulting core file, and if it is added, the content is 1, otherwise 0

Introduction to Linux Core files

Related Article

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.