Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of Linux's core file?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article Xiaobian introduces in detail "what is the use of Linux's core file", the content is detailed, the steps are clear, and the details are handled properly. I hope this "Linux core file what is the use of" article can help you solve your doubts, following Xiaobian's ideas slowly in depth, let's learn new knowledge.

1. Brief introduction of core file

We often hear people say that the program core has dropped and needs to be fixed. Most of what we are talking about here refers to the abnormal exit or termination of the corresponding program during operation due to various exceptions or bug, and when certain conditions are met (why do we say that certain conditions need to be met here? A file called core will be generated.

Usually, the core file will contain the memory, register status, stack pointer, memory management information and all kinds of function call stack information when the program is running. We can understand that the current state of the program is stored to generate the first file, and many programs will produce a core file when it goes wrong. Analyze this file through tools. We can locate the corresponding stack call and other information when the program exits abnormally, find out the problem and solve it in time.

two。 Turn the generation of core files on or off

Use the following command to prevent the system from generating core files

The command below ulimit-c 0 checks whether the option to generate the core file is turned on

Ulimit-a this command displays all user customizations, where the option-a stands for "all".

You can also modify the system file to adjust the core option. There is usually a sentence in / etc/profile to prohibit the generation of core files, which is usually reasonable.

# No core files by defaultulimit-S-c 0 > / dev/null 2 > & 1 but in the process of development, sometimes in order to debug problems, it is still necessary to open the core file in a specific user environment and add ulimit-c unlimited to the user's ~ /. Bash_profile to allow specific users to generate core files if ulimit-c 0 also prohibits the generation of core files, while ulimit-c 1024 limits the size of the generated core files to no more than 1024kb

3. Set the core dump file directory and naming rules for Core Dump

/ proc/sys/kernel/core_uses_pid can control whether pid is added as an extension to the filename of the resulting core file. If so, the file content is 1, otherwise it is 0.

/ proc/sys/kernel/core_pattern can set the location or file name of the formatted core file. For example, if the original file content is core-%e, you can modify it as follows: echo "/ corefile/core-%e-%p-%t" >

/ proc/sys/kernel/core_pattern will control that the resulting core file will be stored in the / corefile directory, and the resulting file name will be 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 add current uid

% g-insert current gid into filename add current gid

% s-insert signal that caused the coredump into the filename adds the signal that causes core to be generated

% t-insert UNIX time that the coredump occurred into filename adds the unix time when the core file was generated

% h-insert hostname where the coredump happened into filename add hostname

% e-insert coredumping executable name into filename add command name

4. Working with core files

Type: gdb-c core in the directory where the core file is located: gdb-c debugger it will start the debugger of GNU to debug the core file, and will display 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 crashed to generate core.12345, then use this instruction to debug: gdb-c core MyServer what to do is to learn the use of gdb

5. A small way to test and generate core files

Enter the instruction directly: kill-s SIGSEGV $$

6. * * Why sometimes programs * * Down, but do not generate * * Core** files.

Under Linux, there are some settings that indicate resources available to the shell and to processes. Can be used

# ulimit-a look at these settings. (ulimit is bash built-in Command)

-an All current limits are reported-c The maximum size of core files created-d The maximum size of a process** ideal 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 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 you can see here, if-c shows: 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 core files.

If a Core file is generated when the program goes wrong, Segmentation fault (core dumped) is displayed.

7. Core Dump** core dump file directory and naming convention

/ proc/sys/kernel/core_uses_pid can control whether pid is added as an extension to the filename of the resulting core file. If so, the file content is 1, otherwise it is 0.

After reading this, the article "what is the use of Linux's core file" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report