A brief analysis of using coredump technology to trace the cause of process crashes in Linux

A brief analysis of using coredump technology to trace the cause of process crashes in Linux

Recently, a problem occurred in the project. The server-side program would suddenly crash and exit. We used coredump technology to find the cause of the crash, that is, to determine which function was being executed when the process exited and its status.

If coredump is enabled on the system, or more precisely, if coredump is enabled on the current shell environment, when the program in the current shell environment crashes and exits, the memory state of the process stack at that time will be written to the core file. Use gdb to view the status of the stack saved in this core file, gdb a.out core. (For more information about coredump and shell, please refer to my other blog "Using dotnet-dump to find the reason why .net core 3.0 occupies 100% of the CPU", and for gdb, please refer to "Use and Summary of gdb Debugging Commands")

The default location of the core file is the location of the executable file, and the default name is core. Its location and name can be set. My settings are:

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

In this way, the generated core file will be placed in the /home/corefile directory, and the core file name will appear in the form of core-%e-%p-%t, where %e represents the name of the executable file, %p represents the process, and %t represents the time when the core file was generated (note that it is Unix time).

Here is a routine that can cause a coredump:

The crossed lines are where the coredump will occur. After execution, the following files will be generated in the /home/corefile directory:

[root@localhostwin7]# ls /home/corefile/ 

a.out is the executable file name, 5082 is the PID, and 1490760381 is the Unix time when the file was generated. Put the a.out and core files in a directory and use the command:

gdb a.out core-a.out-5082-1490760381

Enter gdb and use the backtrace command to view the memory status of the stack when the process exits, as shown below:

It can be seen that when the process exits, the last function executed is the square function. ————————————————

Summarize

The above is what I introduced to you about using coredump technology to trace the cause of process crash under Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time!

<<:  Teach you how to use vscode to build a react-native development environment

>>:  A brief discussion on the use of GROUP BY and HAVING in SQL statements

Recommend

A quick guide to Docker

Docker provides a way to automatically deploy sof...

Implementation of FIFO in Linux process communication

FIFO communication (first in first out) FIFO name...

CSS makes tips boxes, bubble boxes, and triangles

Sometimes our pages will need some prompt boxes o...

Vue improves page response speed through lazy loading

Table of contents Overview What is lazy loading? ...

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docke...

An example of vertical centering of sub-elements in div using Flex layout

1. Flex is the abbreviation of Flexible Box, whic...

How to replace all tags in html text

(?i) means do not match case. Replace all uppercas...

A simple method to implement scheduled backup of MySQL database in Linux

Here are the detailed steps: 1. Check the disk sp...

Reasons and solutions for prompting to save action after uploading files in form

The json data must be returned in html format That...

Linux remote login implementation tutorial analysis

Linux is generally used as a server, and the serv...

MySQL full-text fuzzy search MATCH AGAINST method example

MySQL 4.x and above provide full-text search supp...

Introduction to fourteen cases of SQL database

Data Sheet /* Navicat SQLite Data Transfer Source...

MySQL database master-slave replication and read-write separation

Table of contents 1. Master-slave replication Mas...

Get a list of your top 10 most frequently used terminal commands in Linux

I think the commands I use most often are: Choice...