Program exception processing method, device, equipment and storage medium
By sending signals to the surviving threads and recording call stack information when the program is abnormal, the stack traceability of the entire thread is solved, and the problem of the inability to locate business exceptions in the existing technology is improved, and the positioning and analysis efficiency of the abnormal problem is improved.
Patent Information
- Application Number
- CN202110596062.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-31
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-05-31
AI Technical Summary
The prior art cannot locate business exceptions that will not generate abnormal signals, such as dead loops and blocking suspension, and cannot effectively analyze and resolve these exceptions.
When a business exception is detected, a signal is sent to the currently surviving thread, so that it records the thread identification and call stack information, and restarts the target process after waiting for the preset time, thereby realizing stack traceability of the entire thread and locating the root cause of the business exception. .
Through stack traceback of the entire thread, the efficiency of positioning and analysis of exception problems is improved, the problem of the inability to locate business exceptions in the prior art is solved, and the limitation of only recording threads that generate exception signals is avoided in the prior art.
Smart Images

Figure CN113220535B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer and communication technology, and in particular to a method, device, equipment and storage medium for processing program exceptions. Background Art
[0002] With the development of multi-core CPU technology, a well-designed multi-threaded program can make full use of the computing resources of the multi-core CPU, improve CPU utilization, thereby improving the overall processing efficiency of the program, improving concurrency, etc. Therefore, multi-threaded programs have become the norm for server programs.
[0003] In the actual program development process, it is inevitable that there will be some unexpected exception scenarios that cause program exception problems, such as deadlock, infinite loop, abnormal memory access, slow IO, etc.; in order to locate and solve various program exception problems, the prior art usually adopts a stack backtracking method, that is, when the program starts, registers and takes over the system key signal, and when the exception signal is triggered, the call stack information of the current thread is output to the log file through the stack backtracking function, so that subsequent relevant personnel can analyze the exception stack information of the log file to locate the cause of the program crash exception.
[0004] However, the stack backtracking method used in the prior art can only locate the abnormal problems that cause program crashes, but cannot locate some business abnormalities that are likely to exist in the program and do not generate abnormal signals, such as dead loops, blocking and hanging, etc. Summary of the invention
[0005] The embodiments of the present invention provide a method, device, equipment and storage medium for processing program exceptions, so as to solve the problem that the prior art cannot locate business exceptions that do not generate exception signals.
[0006] In a first aspect, an embodiment of the present invention provides a method for processing a program exception, comprising:
[0007] If the first service is detected to be abnormal, sending a first signal to the currently alive first thread, so that the first thread stores its thread identifier and call stack information after receiving the first signal;
[0008] After waiting for a preset time, restart the target process to which the first service belongs.
[0009] In a second aspect, an embodiment of the present invention provides a program exception processing device, including:
[0010] A first processing module is configured to send a first signal to a currently alive first thread if a first service exception is detected, so that the first thread stores its thread identifier and call stack information after receiving the first signal;
[0011] The second processing module is used to restart the target process to which the first service belongs after waiting for a preset time.
[0012] In a third aspect, an embodiment of the present invention provides an electronic device, including: a memory, a transceiver, and at least one processor;
[0013] The processor, the memory and the transceiver are interconnected via a circuit;
[0014] The memory stores computer-executable instructions; the transceiver is used to receive user configuration information;
[0015] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method described in the first aspect and various possible designs of the first aspect.
[0016] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the method described in the first aspect and various possible designs of the first aspect are implemented.
[0017] The program exception processing method, device, equipment and storage medium provided by the embodiments of the present invention can realize stack backtracing of the entire thread by notifying all surviving threads in the program to record their thread identifiers and call stack information when the program's business exception occurs, making it easier to locate the root cause of the business exception, improving the efficiency of locating and analyzing the abnormal problem, and solving the problem that the prior art cannot locate business exceptions. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0019] Figure 1 A flowchart of a method for processing program exceptions provided by an embodiment of the present invention;
[0020] Figure 2 A schematic diagram of a thread information registration process provided by an embodiment of the present invention;
[0021] Figure 3 A main thread initialization flow chart of a process provided by an embodiment of the present invention;
[0022] Figure 4A schematic diagram of an exemplary overall flow of a method for handling program exceptions provided in an embodiment of the present invention;
[0023] Figure 5 A schematic diagram of the structure of a device for processing program exceptions provided by an embodiment of the present invention;
[0024] Figure 6 A schematic diagram of an exemplary structure of a device for processing program exceptions provided in an embodiment of the present invention;
[0025] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
[0026] The above drawings have shown clear embodiments of the present invention, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present invention in any way, but to illustrate the concept of the present invention for those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] First, the terms involved in the present invention are explained:
[0029] GNU C Library: GNU C Library, also known as glibc (GNU C Runtime Library), is a C compiler released under the LGPL license agreement and is easy to download from the Internet. GNU C Runtime Library is a C function library, which is a collection of APIs used when the program is running. They are generally pre-compiled and exist in the form of binary code in Linux-like systems. GNU C Runtime Library is usually released as a part of the GNU C compiler. The most important application is to cooperate with the Linux kernel and become an important part of the GNU / Linux operating system. The most widely used C function library on the Linux platform is glibc, which includes the implementation of the C standard library and all system functions. Almost all C programs need to call the library functions of glibc, so glibc is the basis for the operation of C programs on the Linux platform. Glibc provides a set of header files and a set of library files. The most basic and most commonly used C standard library functions and system functions are in the libc.so library file. Almost all C programs depend on libc.so for operation. Some C programs that do mathematical calculations depend on libm.so, and multi-threaded C programs depend on libpthread.so.
[0030] Deadlock: When multiple threads access shared resources, they will add mutex locks, read-write locks, spin locks, etc. to protect the operations on shared resources. However, improper use of lock resources can easily cause deadlock problems, resulting in abnormal blocking of the program and inability to continue working.
[0031] Infinite loop: Linked list operations, loop operations, recursive operations, etc. all have the risk of infinite loops. The root cause of the infinite loop may be basic code logic problems, memory access out-of-bounds problems, memory data errors, improper protection of shared resources, etc.
[0032] Abnormal memory access: Illegal operations such as out-of-bounds memory access, repeated release, and wild pointers will have a fatal impact on the program and may cause business logic errors, stack exceptions, and other problems.
[0033] Slow IO: IO operations include disk IO, network IO, etc. Synchronous IO operations will cause the caller to be blocked. In the scenario where the IO operation delay increases, improperly designed programs will cause business logic exceptions.
[0034] In addition, the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. In the description of the following embodiments, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0035] The following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.
[0036] An embodiment of the present invention provides a method for processing program exceptions, which is used for processing program exceptions. The execution subject of this embodiment is a program exception processing device, which can be set in an electronic device, which can be a server or other implementable computer devices.
[0037] like Figure 1 FIG. 1 is a flow chart of a method for handling program exceptions provided in this embodiment, the method comprising:
[0038] Step 101: If a first service exception is detected, a first signal is sent to a currently alive first thread, so that the first thread stores its thread identifier and call stack information after receiving the first signal.
[0039] Specifically, the watchdog thread or other methods can be used to detect whether the business process in the program is abnormal. The watchdog thread can be an independent thread or implemented in the main thread. In actual applications, key businesses that need to be monitored can be defined. Since different programs implement different functions, the definition of key businesses is also different. They can be set according to actual needs, such as heartbeat services between key components (need to monitor whether the heartbeat is normal), timer execution services (need to monitor whether normal execution), network IO blocking time (need to monitor whether the blocking time is too long), etc.
[0040] Each process may include one or more threads. In actual applications, a complete program does not correspond one-to-one to a process. A program may be executed by multiple processes, and each process may also execute multiple programs. The processing of program exceptions in the present invention targets the process. It can be considered that each process corresponds to a subroutine in the program. If a program is completely executed by one process, the subroutine corresponding to the process is the program itself. The method of the present invention can be used to process each process.
[0041] The first service may be any service executed by the target process (which may be the process of executing any subroutine in the execution program), or any key service set according to actual needs. The services are divided according to the program logic functions. The target process includes one or more threads, which may specifically include the main thread and other threads. An independent watchdog thread may be started in each process, or the main thread may execute the watchdog function to detect the service status. If an abnormality is detected in the first service, a relevant signal (which may be called the first signal) may be sent to all currently surviving threads (which may be called the first threads) in the target process through a system command to notify each first thread to change its own thread identifier and call The stack information is recorded, for example, output to a log file. The first signal may be a user-defined signal. When the program starts, the system SIGNAL function is called at the program entry to register the signal management function corresponding to the first signal with the system, so that the system (such as the Linux system) does not adopt the default action but the user-defined action. The thread identifier of the first thread may be a thread ID or a thread name. The call stack information of the thread mainly includes one or more of the following information: file name, function name, function offset address, file offset address, thread name, thread ID, etc., which may be set according to actual needs. The first business exception may include business exception problems such as dead loop and abnormal suspension.
[0042] Optionally, the currently alive threads can be maintained through a thread global table or other feasible methods. For example, during program execution, each thread registers its thread information into a thread global table when it is started, and deletes its thread information from the thread global table before the thread exits, thereby enabling the thread global table to maintain the thread information of the currently alive threads in real time.
[0043] Since the call stack information of all threads can be recorded when a business exception occurs, subsequent relevant personnel can perform stack backtracing through the call stack information, which makes it easier to locate the root cause of the business exception, solving the problem that the prior art cannot locate the business exception. In addition, the stack backtracing method of the prior art can only record the call stack information of the thread that generates the exception signal, while the method of the present invention can realize stack backtracing of the entire thread, effectively improving the efficiency of locating and analyzing the exception problem.
[0044] Step 102: After waiting for a preset time, restart the target process to which the first service belongs.
[0045] Specifically, due to business abnormalities, the target process cannot be executed normally, so the target process needs to be restored. In order to ensure that each thread can record the thread identifier and call stack information, the watchdog thread needs to wait for a certain period of time before restarting the target process to restore the abnormal business processing flow. The preset time can be set according to actual needs. For example, it can be set to 1 second, 2 seconds, etc. according to system performance.
[0046] The method for handling program exceptions provided in this embodiment notifies all surviving threads in the process executing the business to record their thread identifiers and call stack information when a business exception occurs in the program, thereby realizing stack backtracing of the entire thread, facilitating the location of the root cause of the business exception, improving the efficiency of locating and analyzing the exception problem, and solving the problem that the prior art cannot locate business exceptions.
[0047] In order to make the technical solution of the present invention clearer, another embodiment of the present invention further supplements the method provided in the above embodiment.
[0048] As an implementable manner, in order to detect whether related services in the program are abnormal, based on the above embodiment, optionally, the method may further include: a watchdog thread periodically detects whether there is a service abnormality.
[0049] Specifically, a software watchdog is used to periodically detect whether relevant services in the program are abnormal. Relevant services can be set according to actual needs. For example, watchdog monitoring can be set for some key services in the program. Specifically, for each process that executes the program, an independent watchdog thread is set in the process or the watchdog function is implemented by the main thread of the process. For the services of the program executed by the process, a certain dog feeding time can be set for each service. When the service is abnormal and the dog cannot be fed on time, the watchdog timer overflows and generates a reset signal. The watchdog can determine that there is a business abnormality and send a first signal to the currently surviving first thread, so that each first thread can output its thread identification and call stack information to the log file in time to facilitate the location and analysis of the abnormal problem. After the watchdog thread sends the first signal to each first thread, it waits for a preset time to ensure that each first thread can complete the recording of the thread identification and call stack information. Then the watchdog thread can restart the target process to restore the abnormal service.
[0050] The watchdog thread can be a new independent thread started in the target process, or it can be directly implemented in the main thread of the target process. The specific setting can be based on actual needs.
[0051] Further, in order to maintain the current surviving thread status in real time, based on the above embodiment, optionally, if the first service is detected to be abnormal, a first signal is sent to the current surviving first thread, including:
[0052] If the first service is detected to be abnormal, the thread global table is traversed to determine the currently surviving first thread, where the thread global table at least includes thread identifiers of each currently surviving thread; and a first signal is sent to each currently surviving first thread.
[0053] Specifically, during the program running process, the currently surviving threads can be maintained in real time through the thread global table, so that after detecting the first business exception, the watchdog can traverse the thread global table to determine the currently surviving first thread, and then send a first signal to each first thread, so that the first thread outputs its thread identifier and call stack information to the log file; the thread global table can be maintained in any feasible format according to actual needs, the thread global table can be maintained in the memory of the process, and the thread global table includes at least the thread identifiers of each currently surviving thread, so that the watchdog thread can determine which threads need to send the first signal; the thread identifier can be a thread ID or a unique thread name. In order to ensure the uniqueness of the thread name, a thread name with a unique identifier can be configured for each thread, which can be set according to actual needs.
[0054] Furthermore, in order to ensure that the thread global table can maintain the currently alive thread information in real time, the method further includes:
[0055] After each thread is started, its thread information is registered in the thread global table, and the thread information at least includes the thread identifier; before each thread exits, its thread information is deleted from the thread global table.
[0056] Specifically, after the thread is started, its thread information is first added to the thread global table, so that the thread global table maintains the thread in a live state in real time. Before the thread exits, its thread information is deleted from the thread global table, and then the thread exits, thereby ensuring that the thread information maintained in the thread global table is the information of the currently alive threads, avoiding the existence of dead threads in the thread global table, and adding unnecessary work to the watchdog thread.
[0057] For example, Figure 2 As shown, it is a schematic diagram of the thread information registration process provided by this embodiment, wherein pthread_setname_np is used to name the thread, and pthread_t is the thread ID.
[0058] In one implementation, in order to ensure normal use of the first signal, the method further includes: when the target process is started, registering a signal processing function corresponding to the first signal, and initializing a thread global table.
[0059] Specifically, the first signal is a user-defined signal. In order to ensure that the first signal can play the user-defined function in the system, it is necessary to register the program's own signal processing function for the first signal with the system through the system function. Specifically, when the target process is started, the main thread of the target process registers the signal processing function of the first signal at the program entry of the target process. For example, if the first signal is the SIGUSR1 signal, the signal processing function of the SIGUSR1 signal is registered, so that the target process can tell the system kernel which function should be called through the signal processing function. In addition, it is also necessary to initialize the thread global table so that the thread can register its own thread information to the thread global table after it is started.
[0060] For example, Figure 3 As shown, it is a main thread initialization flow chart of the process provided by this embodiment.
[0061] As another practicable manner, the method further includes: if a signal causing a program crash exception is detected, storing call stack information of the current thread.
[0062] Specifically, for signals that may cause program crash exceptions, such as SIGSEGV, SIGABRT, etc., the embodiments of the present invention can also locate the exception problem, and specifically use a stack backtrace method for positioning, that is, if the system detects that a program crash exception is executed by a process, the process is interrupted and a related exception signal (such as SIGSEGV, SIGABRT) is sent to the process. The current thread that generates the exception in the process outputs its own call stack information to the log file for subsequent location analysis of the exception problem. The specific principle will not be repeated here.
[0063] For signals that may cause program crash exceptions, in order to implement stack backtracing, it is also necessary to register signal processing functions of these signals with the system. The specific detection method for causing program crash exceptions is existing technology and will not be described in detail here.
[0064] The method of the present invention can not only locate the abnormal problem that causes the program crash, but also realize full-thread stack backtracing in combination with the watchdog thread, thereby realizing the location of the problem that does not cause the program abnormal crash, such as dead loop, abnormal hanging and other problems, while the existing watchdog solution can only detect the business abnormality and restart, but cannot locate the abnormal problem; in addition, the method of the present invention can realize full-thread stack backtracing, and will not introduce the problem of occupying too much disk space and too long business interruption time while recording all thread call stack information. Therefore, the method of the present invention also solves the problem that the existing core dump solution occupies too much disk space and the business interruption time is too long.
[0065] As another feasible manner, in order to determine the abnormal problem, the method also includes: after the first thread receives the first signal, outputting its thread identifier and call stack information to a log file; and locating and analyzing the abnormal problem of the target process based on the thread identifier and call stack information in the log file.
[0066] Specifically, the log file can be a system log file. In the event of an exception, the thread identifier and call stack information are output to the system log file. Subsequently, the exception problem of the target process can be located and analyzed based on the thread identifier and call stack information in the system log file. Specifically, when an exception signal is triggered, the thread call stack information is output to the log file through the stack backtracking function provided by the GNU C Library (i.e., the GNU C library). When relevant personnel need to analyze, they can check the log file, and the cause of the exception can be located by analyzing the exception stack information in the log file.
[0067] For call stack information, the thread can call the backtrace function to obtain its call stack information, store it in a pointer array, and then use a series of backtrace-related functions (backtrace_symbols, backtrace_symbols_fd) to convert the obtained call stack information into printable string information (including function name, function offset address, actual return value) to complete the stack backtrace.
[0068] It should be noted that the various practicable methods in this embodiment may be implemented separately, or may be combined in any combination without conflict to implement the present invention without limitation.
[0069] The overall process of the method of the present invention is described below with an exemplary embodiment. Figure 4 FIG. 1 is a schematic diagram of an exemplary overall flow chart of a method for handling program exceptions provided in this embodiment. For each process of executing a program, the method specifically includes:
[0070] 1. When the process starts, you need to register the program's own signal processing function before creating the thread.
[0071] 2. Initialize the thread global table, such as the thread ID global table.
[0072] 3. Initialize and start other business processes.
[0073] Specifically, for each thread, after startup, it can be named through pthread_setname_np, and the thread ID of the thread (such as pthread_t) can be registered to the thread ID global table, and then the processing logic of the thread is entered. Before the thread exits, the thread information of the thread is deleted from the thread ID global table, and then the thread exits.
[0074] 5. The watchdog thread periodically detects whether the business is abnormal.
[0075] 6. When a service anomaly is detected, the watchdog thread traverses the global table of thread IDs and sends a SIGUSR1 signal to each surviving first thread one by one through the system command pthread_kill. After receiving the SIGUSR1 signal, the first thread performs a stack backtrace, that is, outputs its thread information and call stack information to the system log file. After the traversal, the watchdog thread waits for a preset time (such as 1 second) and then restarts the process to resume the service. pthread_kill is a system command that can be used to send messages between multiple threads.
[0076] 7. When a signal that can cause a program crash exception (SIGSEGV, SIGABRT, etc.) is detected, the current thread that generates the exception outputs its own call stack information to the system log file, that is, the exception problem is solved by stack backtracing.
[0077] The specific operations of the above steps have been described in detail in the above content and will not be repeated here.
[0078] The program exception processing method provided in this embodiment realizes full-thread stack backtracing of business exception problems by combining the watchdog with the full-thread stack backtracing, effectively improving the efficiency of abnormal problem location and analysis, and maintains the current surviving threads in real time through the thread global table, effectively ensuring the realization of full-thread stack backtracing.
[0079] Still another embodiment of the present invention provides a program exception processing device, which is used to execute the method of the above embodiment.
[0080] like Figure 5 FIG. 2 is a schematic diagram of the structure of the apparatus for processing program exceptions provided in this embodiment. The apparatus 30 includes: a first processing module 31 and a second processing module 32 .
[0081] Among them, the first processing module is used to send a first signal to the currently surviving first thread if an abnormality of the first business is detected, so that the first thread stores its thread identifier and call stack information after receiving the first signal; the second processing module is used to restart the target process belonging to the first business after waiting for a preset time.
[0082] Specifically, the first processing module can be connected to a detection module that detects whether the business is abnormal. After the detection module detects that the first business is abnormal, it can notify the first processing module. The first processing module sends a first signal to the currently surviving first thread, so that after the first thread receives the first signal, it will store its thread identifier and call stack information. After the first processing module sends the first signal to the first thread, it can notify the second processing module. The second processing module waits for a preset time and then restarts the subroutine belonging to the first business, that is, restarts the target process.
[0083] In actual applications, the first processing module and the second processing module are respectively the first sub-module and the second sub-module in the watchdog module executed by the watchdog thread, that is, the watchdog thread is used to send a first signal to the currently surviving first thread if a first business abnormality is detected, so that after the first thread receives the first signal, its thread identifier and call stack information are stored, and the watchdog thread restarts the target process after waiting for a preset time.
[0084] Regarding the device in this embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and can achieve the same technical effect, so it will not be elaborated here.
[0085] In order to make the device of the present invention more clear, another embodiment of the present invention further supplements the device provided by the above embodiment.
[0086] like Figure 6 FIG. 1 is a schematic diagram of an exemplary structure of a program exception processing device provided in this embodiment.
[0087] As an implementable manner, in order to detect whether related services in the program are abnormal, based on the above embodiment, optionally, the device further includes a detection module 33.
[0088] The detection module is used to periodically detect whether there are any business anomalies.
[0089] Specifically, the first processing module is the first submodule in the watchdog module, the second processing module is the second submodule in the watchdog module, and the detection module is the third submodule in the watchdog module. The detection module periodically detects whether there is a business abnormality. If a first business abnormality is detected, the first processing module is notified. The first processing module sends a first signal to the currently surviving first thread. After receiving the first signal, the first thread stores its thread identifier and call stack information. After sending the first signal to each first thread, the first processing module can notify the second processing module. The second processing module waits for a preset time and then restarts the target process.
[0090] Furthermore, in order to maintain the current surviving thread status in real time, the first processing module is specifically used to:
[0091] If the first service is detected to be abnormal, the thread global table is traversed to determine the currently surviving first thread, where the thread global table at least includes thread identifiers of each currently surviving thread; and a first signal is sent to each currently surviving first thread.
[0092] Specifically, the system maintains the status of currently surviving threads in real time through a thread global table. After detecting a first business exception, the first processing module can traverse the thread global table to determine the currently surviving threads (i.e., first threads) and send a first signal to each first thread; specifically, the first processing module sends the first signal to each first thread through the communication method between the watchdog thread and other threads.
[0093] Furthermore, in order to ensure that the thread global table can maintain the currently existing thread information in real time, the device also includes: a thread information registration module 34 and a thread information deletion module 35.
[0094] Among them, the thread information registration module is used to register its thread information into the thread global table after the thread is started, and the thread information at least includes the thread identifier; the thread information deletion module is used to delete its thread information from the thread global table before the thread exits.
[0095] Specifically, each thread in the program may include a thread information registration module and a thread information deletion module. After the thread is started, the thread information registration module registers the thread information into the thread global table. Before the thread exits, the thread information deletion module deletes its thread information from the thread global table.
[0096] In one implementation, in order to ensure normal use of the first signal, the device further includes:
[0097] The registration module is used to register the signal processing function corresponding to the first signal and initialize the thread global table when the target process is started.
[0098] Specifically, when the target process is started, the registration module may register the signal processing function corresponding to the first signal with the system and initialize the thread global table.
[0099] In some implementations, the device may further include a storage module for storing the thread global table as another implementable manner. To improve the security of the system, the device may further include:
[0100] The third processing module is used to store the call stack information of the current thread if a signal causing a program crash exception is detected.
[0101] As another feasible method, after receiving the first signal, the first thread outputs its thread identifier and call stack information to the log file; accordingly, the device also includes: a fourth processing module, which is used to locate and analyze the abnormal problem of the target process based on the thread identifier and call stack information in the log file.
[0102] Specifically, each thread may include an output module, which is used to output its thread identifier and call stack information to a log file after receiving a first signal. When positioning analysis is required, the fourth processing module displays the thread identifier and call stack information in the log file to relevant personnel, who then perform positioning analysis on the abnormal problems of the target process.
[0103] It should be noted that the various practicable methods in this embodiment may be implemented separately, or may be combined in any combination without conflict to implement the present invention without limitation.
[0104] Regarding the device in this embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and can achieve the same technical effect, so it will not be elaborated here.
[0105] Another embodiment of the present invention provides an electronic device for executing the method provided in the above embodiment. The electronic device may be a server or other implementable computer device.
[0106] like Figure 7 FIG. 5 is a schematic diagram of the structure of an electronic device provided in this embodiment. The electronic device 50 includes: a memory 51 , a transceiver 52 and at least one processor 53 .
[0107] Among them, the processor, memory and transceiver are interconnected through circuits; the memory stores computer execution instructions; the transceiver is used to receive user configuration information; at least one processor executes the computer execution instructions stored in the memory, so that at least one processor executes the method provided in any of the above embodiments.
[0108] Specifically, the configuration information may include relevant information required for program execution, such as the configuration rules for the thread name configured by the user. The transceiver sends the configuration information to the processor, the processor stores it in a preset area, and the processor reads and executes the computer execution instructions stored in the memory to implement the method provided in any of the above embodiments.
[0109] The electronic device of the present invention can be applied to the exception handling scenario of any program. On the basis of locating the abnormal problem that causes the program crash, it can also locate the problems such as deadlock and abnormal suspension that will not cause the program crash, so as to facilitate the relevant personnel to analyze the root cause behind the hidden problem, and realize full thread stack backtracing, effectively improve the efficiency of positioning analysis, and solve the problem that the prior art cannot locate the business anomaly that does not generate abnormal signals.
[0110] It should be noted that the electronic device of this embodiment can implement the method provided by any of the above embodiments and can achieve the same technical effect, which will not be described in detail here.
[0111] Yet another embodiment of the present invention provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method provided in any of the above embodiments is implemented.
[0112] It should be noted that the computer-readable storage medium of this embodiment can implement the method provided by any of the above embodiments and can achieve the same technical effect, which will not be repeated here.
[0113] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0114] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art that are not disclosed by the present invention. The description and examples are to be considered exemplary only, and the true scope and spirit of the present invention is indicated by the following claims.
[0115] It should be understood that the present invention is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A method for processing program exceptions, characterized in that: include: The watchdog thread periodically detects whether there are business anomalies; If the first service is detected to be abnormal, traverse the thread global table to determine the currently surviving first thread, wherein the thread global table includes at least thread identifiers of each currently surviving thread; For each currently alive first thread, a user-defined first signal is sent to the first thread, so that the first thread stores its thread identifier and call stack information after receiving the first signal, and the first business exception is a business exception that does not cause a program crash and does not generate an exception signal; The watchdog thread restarts the target process to which the first service belongs after waiting for a preset time.
2. The method according to claim 1, characterized in that The method further comprises: After each thread is started, its thread information is registered in the thread global table, where the thread information at least includes a thread identifier; Before each thread exits, its thread information is deleted from the thread global table.
3. The method according to claim 1, characterized in that: The method further comprises: When the target process is started, a signal processing function corresponding to the first signal is registered, and the thread global table is initialized.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: If a signal causing a program crash exception is detected, the call stack information of the current thread is stored.
5. A program exception processing device, characterized in that: include: Watchdog module, used to execute watchdog thread; The watchdog module specifically includes: The detection module is used by the watchdog thread to periodically detect whether there are business anomalies; A first processing module is configured to, if the watchdog thread detects a first business exception, traverse a thread global table to determine a currently surviving first thread, wherein the thread global table at least includes thread identifiers of each currently surviving thread; and send a first signal to each currently surviving first thread, so that the first thread stores its thread identifier and call stack information after receiving the first signal, wherein the first business exception is a business exception that does not cause a program crash and does not generate an exception signal; The second processing module is used for the watchdog thread to restart the target process to which the first service belongs after waiting for a preset time.
6. The device according to claim 5, characterized in that The device also includes: A thread information registration module, used to register the thread information of a thread into the thread global table after the thread is started, wherein the thread information at least includes a thread identifier; The thread information deletion module is used to delete the thread information from the thread global table before the thread exits.
7. An electronic device, characterized in that: include: A memory, a transceiver, and at least one processor; The processor, the memory and the transceiver are interconnected via a circuit; The memory stores computer-executable instructions; The transceiver is used to receive configuration information of the user; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 4.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 4 is implemented.
