Handle alarm method, device, electronic device, storage medium and program product

By monitoring and alerting handle usage in the kernel state, the problem of high CPU performance consumption caused by handle usage monitoring in the existing technology is solved, efficient handle alarming and resource isolation are achieved, performance consumption is reduced and processing efficiency is improved.

CN118409940BActive Publication Date: 2024-09-03UNIONTECH SOFTWARE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410888263.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-03
Publication Date
2024-09-03
Estimated Expiration
2044-07-03

AI Technical Summary

Technical Problem

When monitoring the usage of process handles, the existing technology requires frequent polling of the kernel interface, resulting in high CPU performance consumption. Especially when there are many system processes, the time complexity is O(n²), resulting in excessive performance consumption.

Method used

Implement the handle alarm method in the kernel mode of the operating system. By obtaining the current number of handles before allocating handles to the user mode process, and sending alarm information to the user mode process when the number of handles exceeds the alarm threshold, it avoids repeated polling in the user mode. Monitor and alert handle usage directly in kernel mode.

Benefits of technology

It reduces the performance consumption caused by alarms, improves monitoring accuracy, reduces frequent switching between user mode and kernel mode, significantly reduces performance consumption, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409940B
    Figure CN118409940B
Patent Text Reader

Abstract

The present disclosure relates to a handle alarm method, device, electronic device, storage medium and program product. The handle alarm method is applied to the kernel state of an operating system. The handle alarm method includes: in response to obtaining the current handle number before allocating a handle to a first user state process, wherein the current handle number indicates the number of handles already used by the first user state process; when determining that the current handle number exceeds an alarm threshold, sending an alarm message to a second user state process, wherein the alarm threshold is less than the maximum number of handles of the process. The present disclosure does not require repeated polling in the user state, and can greatly reduce performance consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computers, and in particular to a handle alarm method, device, electronic device, storage medium and program product. Background Art

[0002] In the Linux system, when an application opens a file, the kernel generates a handle to represent the file. However, the operating system limits the number of handles that a single process can open (the default is 1024, which can be modified through the OS). If a process continues to use handles but does not recycle them, once the number of used handles exceeds the limit, it will cause the file to fail to open or create, and then cause the business program corresponding to the process to fail.

[0003] To reduce the risk of business program failure, related technologies usually monitor the use of process handles. Specifically, programs are developed in user mode, all processes under the kernel interface / proc are polled continuously, and the number of handles under the / proc / PID_XXX / fd directory is counted. At the same time, an alarm value is set (for example, 80% of the limit threshold). When the number of handles used by a process exceeds the alarm value, an alarm message is sent, and the developer analyzes the process to find out the reason for the exhaustion of handles.

[0004] However, this solution requires actively polling the processes under / proc at certain time intervals in user mode, and in order to maintain accuracy, the interval time (sleep) between two pollings is often controlled within 1 second. In addition, it involves two layers of polling, / proc and / proc / PID_XXX / fd, and the time complexity is O(n²). That is to say, when the number of processes n in the system is larger, the pressure on the CPU to monitor the use of process handles will be greater (quadratic order), resulting in great performance consumption. Summary of the invention

[0005] The present disclosure provides a handle alarm method, device, electronic device, storage medium and program product to at least solve the problem of how to reduce the performance consumption generated by alarms in related technologies.

[0006] According to a first aspect of an embodiment of the present disclosure, a handle alarm method is provided, which is applied to the kernel state of an operating system, and the handle alarm method comprises: before allocating a handle to a first user state process, obtaining a current handle number, wherein the current handle number represents the number of handles already used by the first user state process; and when it is determined that the current handle number exceeds an alarm threshold, sending an alarm message to a second user state process, wherein the alarm threshold is less than the maximum number of handles of the process.

[0007] Optionally, sending the alarm information to the second user state process includes: acquiring process information of the first user state process; and sending the alarm information including the process information to the second user state process.

[0008] Optionally, the obtaining process information of the first user state process includes: obtaining a digital identifier, a name, the current handle number, and call stack information of the first user state process as the process information.

[0009] Optionally, the operation of obtaining the call stack information of the first user state process includes: obtaining register information; and performing a stack backtracing operation on a function call stack frame structure according to the register information to obtain the call stack information of the first user state process.

[0010] Optionally, performing a stack backtracing operation on the function call stack frame structure according to the register information to obtain the call stack information of the first user state process includes: determining the current frame from the function call stack frame structure according to the register information; determining the frame information of the current frame and the call frame that calls the current frame; using the call frame as the new current frame and continuing to perform the steps of determining the frame information of the current frame and the call frame that calls the current frame until a new call frame cannot be determined; using the frame information of each frame that has a call relationship as the call stack information of the first user state process.

[0011] Optionally, the handle alarm method further includes: establishing a two-way communication connection with the second user state process; and receiving the alarm threshold sent by the second user state process based on the two-way communication connection.

[0012] According to a second aspect of an embodiment of the present disclosure, a handle alarm device is provided, which is applied to the kernel state of an operating system, and the handle alarm device includes: an acquisition unit, configured to acquire a current number of handles before allocating a handle to a first user state process, wherein the current number of handles represents the number of handles already used by the first user state process; an alarm unit, configured to send an alarm message to a second user state process when it is determined that the current number of handles exceeds an alarm threshold, wherein the alarm threshold is less than the maximum number of handles of the process.

[0013] Optionally, the alarm unit is further configured to: obtain process information of the user state process; and send the alarm information including the process information to the second user state process.

[0014] Optionally, the alarm unit is further configured to obtain a digital identifier, a name, the current number of handles, and call stack information of the first user-mode process as the process information.

[0015] Optionally, the alarm unit is further configured to: obtain register information; and perform a stack backtrace operation on a function call stack frame structure according to the register information to obtain the call stack information of the first user state process.

[0016] Optionally, the alarm unit is also configured to: determine the current frame from the function call stack frame structure according to the register information; determine the frame information of the current frame and the calling frame that calls the current frame; use the calling frame as the new current frame, and continue to execute the steps of determining the frame information of the current frame and the calling frame that calls the current frame until a new calling frame cannot be determined; and use the frame information of each frame that has a calling relationship as the call stack information of the first user state process.

[0017] Optionally, the handle alarm device further includes: a connection unit configured to establish a two-way communication connection with the second user state process; and a receiving unit configured to receive the alarm threshold sent by the second user state process based on the two-way communication connection.

[0018] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: at least one processor; and at least one memory storing computer executable instructions, wherein the computer executable instructions, when executed by the at least one processor, prompt the at least one processor to execute a handle alarm method according to an exemplary embodiment of the present disclosure.

[0019] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor is prompted to execute a handle alarm method according to an exemplary embodiment of the present disclosure.

[0020] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, comprising computer instructions, which, when executed by at least one processor, prompt the at least one processor to execute a handle alarm method according to an exemplary embodiment of the present disclosure.

[0021] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects: according to the handle alarm method, device, electronic device, storage medium and program product of the present disclosure, by directly obtaining the current number of handles of the first user state process before the kernel allocates a handle to the first user state process, and then alerting the second user state process when it is determined that the current number of handles exceeds the alarm threshold, it is possible to actively alert the user state process before the handle is officially allocated, without the need for repeated polling in the user state, which can greatly reduce performance consumption.

[0022] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.

[0024] Figure 1 is a flowchart of a handle alarm method according to an exemplary embodiment of the present disclosure.

[0025] Figure 2 is a diagram showing the internal structure of a kernel during runtime according to a specific embodiment of the present disclosure.

[0026] Figure 3 The figure is a schematic diagram of a stack backtrace based on a frame pointer according to a specific embodiment of the present disclosure.

[0027] Figure 4 is a block diagram of a handle alarm device according to an exemplary embodiment of the present disclosure.

[0028] Figure 5 is a block diagram of an electronic device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0029] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0030] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The implementation methods described in the following examples do not represent all implementation methods consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the attached claims.

[0031] It should be noted that the phrase "at least one of the items" in the present disclosure includes three types of parallel situations: "any one of the items", "a combination of any number of the items", and "all of the items". For example, "including at least one of A and B" includes the following three types of parallel situations: (1) including A; (2) including B; (3) including A and B. Another example is "executing at least one of step 1 and step 2" which means the following three types of parallel situations: (1) executing step 1; (2) executing step 2; (3) executing step 1 and step 2.

[0032] Hereinafter, a handle alarm method, apparatus, electronic device, storage medium, and program product according to exemplary embodiments of the present disclosure will be described in detail with reference to the accompanying drawings.

[0033] Figure 1 The flowchart of the handle alarm method according to the exemplary embodiment of the present disclosure is shown in FIG. The handle alarm method is applied to the kernel state of the operating system and is specifically executed by the kernel code.

[0034] Specifically, in computer science, the operating system kernel is the core part of the system software, which is responsible for managing the system's resources and providing access to these resources. The kernel is not a physical "core", but a collection of specific codes that implement the core functions of the operating system, such as process management, memory management, file system management, device drivers, etc. A process refers to an instance of a user-mode program running in the operating system, and is therefore also called a user-mode process. A user-mode program refers to an application or task that runs as a user in the operating system, including user applications such as text editors and browsers, as well as some system services and daemons. These programs are usually written or installed by users and interact with hardware and system resources through the operating system's interface. A user-mode program is part of a user-mode process and is the specific execution code carried by the user-mode process. A user-mode program can create one or more user-mode processes at runtime, and a user-mode process can also contain multiple user-mode programs at the same time.

[0035] There are two different operating modes in the operating system: kernel mode and user mode. Kernel mode is the mode in which the kernel of the operating system runs. In kernel mode, the code can execute any CPU instruction and access any memory address. All core functions such as hardware resource management, process scheduling, and memory management are executed in kernel mode. User mode means that the program runs in a restricted mode that is strictly controlled by the hardware and the operating system. User-mode processes cannot directly access hardware resources or execute privileged instructions. They can only request services from the kernel through system calls. For example, when a user-mode process needs to open a file, it will request the kernel to open the file through a system call. In the process of executing the operation, the kernel will allocate a handle to the file to be opened for the user-mode process and return it to the user-mode process so that the user-mode process can use the handle to request other operations on the corresponding file, such as reading the contents of the file.

[0036] As introduced in the background technology section, the operating system will limit the number of handles opened by a single process. In order to reduce the risk of business program failure due to excessive handle usage, related technologies usually develop programs in user mode to continuously poll the kernel for currently running processes and obtain the number of handles used by each process. This method requires frequent and active data requests from the kernel in user mode, which will cause great performance consumption due to context switching overhead, permission checks, and mode switching.

[0037] Specifically, regarding context switching overhead, when a user-mode process needs to execute a system call, control must be transferred to kernel mode, which results in a context switch from user mode to kernel mode. Context switching involves saving the current user-mode context information, including register contents, stack information, etc., and then loading the kernel-mode context and executing kernel-mode code. After the system call is completed, another context switch from kernel mode back to user mode is required. Regarding permission checks, when a user-mode process executes a system call, the kernel must perform a permission check to ensure that the user has the right to perform the operation, which may involve operations such as verifying parameters and checking permissions, adding additional processing time. Regarding mode switching, the kernel needs to switch to the privileged mode of kernel mode during the execution of a system call, which involves the overhead of CPU mode switching.

[0038] Reference Figure 1 In step 101, before allocating a handle to the first user state process, the current handle number is obtained. The current handle number indicates the number of handles already used by the first user state process.

[0039] It should be noted that the first user state process does not specifically refer to a certain process, but represents the process that currently needs to allocate a handle. Therefore, each time the handle alarm method according to the exemplary embodiment of the present disclosure is executed, the first user state process involved may be the same or different.

[0040] Unlike the related art that frequently polls the kernel in user mode, the handle alarm method according to the exemplary embodiment of the present invention directly obtains the number of handles already used by the current first user mode process in kernel mode. Since operations within kernel mode can directly access system resources, frequent switching between user mode and kernel mode is avoided, thereby greatly reducing background noise performance consumption. Moreover, since there is no time difference in polling, the accuracy can also be effectively improved.

[0041] In addition, since the file created by the first user-state process is bound to the first user-state process, it can only be accessed and operated by the first user-state process (specifically, the access and operation are achieved through the kernel, and the emphasis here is that it cannot be accessed and operated by other user-state processes), thereby achieving process-level resource isolation.

[0042] In step 102, when it is determined that the current number of handles exceeds the alarm threshold, an alarm message is sent to the second user state process.

[0043] By alerting the second user state process when it is determined that the current handle number of the first user state process is large, the second user state process can be informed of the emergency situation of the handle usage of the first user state process in a timely manner. It should be understood that, unlike the related art in which a process in the user state (usually a process dedicated to alerting, so as to centrally query and alert multiple user state processes running in the operating system) needs to initiate polling to the kernel on its own, in the handle alert method according to the exemplary embodiment of the present disclosure, the second user state process only needs to wait for the alert information sent by the kernel. The second user state process can be a process different from the first user state process, for example, similar to the related art, as a process dedicated to alerting; the second user state process can also be the first user state process itself that currently needs to allocate a handle, thereby sending an alert message to the first user state process, and the present disclosure does not limit this.

[0044] In addition, by using the timing of each handle allocation as a trigger condition for obtaining the current number of handles in kernel mode, it is possible to configure clear and practical trigger conditions for this operation and achieve continuous attention to the use of handles. At the same time, when it is determined that an alarm is required based on the current number of handles obtained (that is, the current number of handles exceeds the alarm threshold), an alarm message is immediately sent to the second user mode process, and an alarm can be initiated as soon as the number of handles used reaches the warning amount, thereby effectively ensuring the timeliness of the alarm.

[0045] Specifically, the alarm threshold is less than the maximum number of process handles, which is the maximum number of handles that a single process is allowed to open, for example, the default value is 1024. The alarm threshold that is less than the maximum number of process handles can achieve effective alarms at an earlier stage before the business program fails. As an example, the alarm threshold is the product of the maximum number of process handles and a preset ratio (for example, but not limited to 70%, 75%, 80%), or the difference obtained by subtracting 1 from the product. In other words, a product is determined based on the preset ratio, and the alarm threshold can be adjusted accordingly as the maximum number of process handles is adjusted. The product can be directly used as the alarm threshold, so that an alarm is issued when the current number of handles exceeds the product, which means that the first user state process has used the handles of the product number; the difference obtained by subtracting 1 from the product can also be used as the alarm threshold, so that an alarm is issued when the sum of the current number of handles plus 1 exceeds the product, which means that if handles continue to be allocated to the first user state process, the number of handles used by the first user state process will exceed the product. The impact of the two on the alarm effect is not much different, and the present disclosure does not limit this. Of course, other reasonable values ​​can also be used as the alarm threshold.

[0046] It should be understood that in step 102, the current number of handles exceeds the alarm threshold, which means that the current number of handles is greater than or equal to the alarm threshold, so that an alarm message can be sent when the current number of handles gradually increases to the alarm threshold, and at this time, handles can be temporarily not allocated to the first user state process. Whether to allocate and when to allocate later is not the focus of this disclosure, so it is not limited. If it is determined that the current number of handles is less than the alarm threshold, handles can be allocated to the first user state process.

[0047] Next, the handle alarm method according to the exemplary embodiment of the present disclosure is further introduced.

[0048] Since the related technology periodically polls the kernel for the handle usage of each process, after the polling and alarm, the scene where the number of used handles just exceeds the alarm value has disappeared and cannot be traced back, so generally testing means or problem reproduction are used, and debug programs are used to obtain call stacks and analyze the problems. However, the on-site problems may not be reproduced, and replacing the debug program in the production environment will also result in a longer positioning and analysis cycle and higher costs.

[0049] To solve this problem, optionally, the operation of sending the alarm information to the second user state process in step 102 includes: obtaining the process information of the first user state process; sending the alarm information containing the process information to the second user state process. The process information is information describing the first user state process. By obtaining and sending the process information of the first user state process at the same time as the alarm, it is possible to capture relevant information before the scene disappears, and to achieve effective positioning analysis of abnormal use of handles. At this time, there is no need to use testing means, nor is there a need to replace the production environment with a debug program, which helps to shorten the positioning analysis cycle and reduce the positioning analysis cost. Specifically, when the second user state process obtains the alarm information containing the process information, it can be understood that the process has a large number of handles in use, which is often caused by some handles not being closed in time. Therefore, it can be used for users to combine the process information to locate the user state program fragments that may not have closed the handles in time, and then modify these program fragments to close the handles that are no longer needed in time.

[0050] Further optionally, the above-mentioned operation of obtaining the process information of the first user state process includes: obtaining the digital identifier, name, current handle number, and call stack information of the first user state process as process information. The digital identifier (PID, Process Identifier) ​​is also called the process identifier, which is a unique number assigned by the operating system to each running process and is used to uniquely identify a process. Through the digital identifier, the operating system and the user can manage and control the process, such as sending a signal, checking the status, or terminating the process. The name is also called the process name (command, abbreviated as COMM), which represents the command name or executable file name of the process and is used to identify the type or purpose of the process. The current handle number intuitively reflects the handle usage of the first user state process. The call stack information describes the current function call stack frame structure, which can allow the user to understand the specific situation of the currently executed function, so as to locate the corresponding function. By using the above information as process information, the user can fully understand the running status of the first user state process, and provide a reliable basis for positioning analysis, which helps to improve the efficiency of positioning analysis.

[0051] Further optionally, the above-mentioned operation of obtaining the call stack information of the first user state process includes: obtaining register information; performing a stack backtracking operation on the function call stack frame structure according to the register information to obtain the call stack information of the first user state process. The function call stack is a mechanism used by a computer program to track function calls during execution. When a function is executed, each time a function is called, the called function and its parameters, local variables and other information are stored in the stack to form a stack frame; when the function execution ends, the corresponding stack frame will be popped out, and the control right returns to the last called function. The function call stack can be regarded as a stack structure for storing function call information, which records the function call sequence and context information during the program running process, which is very helpful for program debugging and error troubleshooting. The register information describes the information of the registers used to save different information in the function call stack frame structure. Based on the register information, it is possible to trace back along the function call path from the currently executing frame in the function call stack frame structure, thereby obtaining the information of the entire call stack.

[0052] Further optionally, the above-mentioned operation of performing a stack backtrace operation on the function call stack frame structure according to the register information to obtain the call stack information of the first user state process includes: determining the current frame from the function call stack frame structure according to the register information; determining the frame information of the current frame and the call frame that calls the current frame; using the call frame as the new current frame, and continuing to perform the steps of determining the frame information of the current frame and the call frame that calls the current frame until a new call frame cannot be determined; using the frame information of each frame that has a call relationship as the call stack information of the first user state process. By determining the call frame from the current frame, and then using the call frame as the new current frame, and continuing to backtrace the call frame, it is possible to backtrace step by step to find the most root call frame currently being executed, and use the frame information of these frames as a whole as the call stack information of the first user state process, so that users can locate the corresponding function based on these frames, which helps to achieve accurate positioning and find the problem.

[0053] As an example, register information may include information such as fp (Frame Pointer), sp (Stack Pointer), and lr (Link Register). The fp register is a base pointer used to save the current function call stack frame structure. It points to the stack frame of the current function, that is, the storage area of ​​the function local variables and other related information. Through the fp register, the program can access the function parameters, local variables, and other data related to the function execution. The sp register is a pointer used to save the current stack top position. Through the sp register, the program can manage the growth and contraction of the stack, as well as perform function calls and return operations. The lr register is a register used to save the return address after the function call. When the function is called, the address of the next instruction to be returned is stored in the lr register. When the function is executed, the return address can be found through the lr register, so as to continue to execute the next instruction of the calling function. Since the function call often returns to other functions that call the function after the function call ends, the call frame that calls the current frame can be determined based on this.

[0054] In addition to the above-mentioned steps 101 and 102, optionally, the handle alarm method according to the exemplary embodiment of the present disclosure further includes: establishing a two-way communication connection with a second user state process; based on the two-way communication connection, receiving an alarm threshold sent by the second user state process. It should be understood that for the aforementioned embodiment of determining the alarm threshold based on the product of the maximum number of process handles and a preset ratio, what is received here is specifically a preset ratio. By establishing a two-way communication connection between the kernel and the second user state process, and receiving the alarm threshold sent by the second user state based on the connection, the user can set the alarm threshold. As an example, the kernel can also receive an updated alarm threshold sent by the second user state process based on the two-way communication connection, thereby realizing the modification of the alarm threshold.

[0055] Next, combine Figure 2 and Figure 3 A handle alarm method according to a specific embodiment of the present disclosure is introduced. Figure 2 is a diagram showing the internal structure of a kernel during runtime according to a specific embodiment of the present disclosure.

[0056] This specific embodiment includes the following three core steps.

[0057] Step 1: Establish a communication channel and set the alarm threshold.

[0058] This step establishes communication between the kernel and the second user state process through netlink. The second user state process sends a message to the kernel to set an alarm threshold, specifically, to set a preset ratio P and preset a custom data storage MAP (Memory Array Processor).

[0059] Specifically, the threshold check module in the kernel initializes a resident memory to save the preset ratio of the alarm threshold (for example, 80%), and provides an external interface threshold_modify() for modifying the preset ratio. In kernel mode, fd_link.ko creates a socket of type AF_NETLINK, and in user mode, the alarm module creates a socket of type AF_NETLINK to establish two-way communication. The alarm module in user mode sends a message to the fd_netlink module in kernel mode through netlink, and the fd_netlink module calls threshold_modify() to modify the preset ratio of the alarm threshold.

[0060] Step 2: Check the handle usage.

[0061] This step obtains the number of handles used by the corresponding first user state process each time the kernel allocates a handle, as the current number of handles. If the current number of handles exceeds the alarm threshold (the maximum number of process handles × P), the CPU register information fp, sp, and lr are obtained at this time, and the entire call stack information of the current first user state process is obtained through stack backtracing operations, and the call stack information is written into storage S. The kernel calls get_current to obtain the task information on the CPU, and obtains the process PID and process name COMM on the CPU.

[0062] Specifically, when the first user-mode process calls a system call to allocate a handle, the operation is implemented in the kernel by __alloc_fd, and before allocating the handle, the kernel first enters the process traceback module (process_traceback). The traceback module will first use PCB (Process Control Block, which is used to record the external characteristics of the process and describe the movement and change process of the process. It is the only sign that the system perceives the existence of the process) to judge the handle information. If (the current number of handles + 1) < the maximum number of process handles × P, it means that the alarm threshold is not exceeded, and the handle is allocated. On the contrary, if the alarm threshold is exceeded, the current handle number FD_NUM is recorded, and get_current() is first called to obtain the PID and process name COMM of the executing process (the information is retained in the PCB), and then task_pt_regs() is used to obtain the CPU registers fp, sp, lr, etc. of the user space runtime (User SpaceRuntime, user space is the non-privileged execution environment provided by the operating system to the user state process, corresponding to the concept of user state) (this information is stored in the kernel stack of the process), and the instruction address of each function in the first user state process is obtained through stack backtracing.

[0063] Figure 3 is a schematic diagram of a stack backtracking based on a frame pointer according to a specific embodiment of the present disclosure, such as Figure 3 As shown in the figure, the stack frame structure of a function call includes multiple stack frames, namely, the earlier frame, the calling frame, and the current frame. The earlier stack frame is closer to the bottom of the stack. Each stack frame includes multiple areas for storing different data. The stack pointer (sp) points to the current position at the top of the stack. Figure 3 The frame pointer (fp) points to a fixed position relative to the current frame, providing a fixed reference point that helps simplify access to local variables and parameters in the current frame. It usually points to a fixed area in the stack frame, such as the area that holds the previous frame pointer (that is, the frame pointer of the calling frame, i.e. Figure 3 The frame pointer saved in the function call frame points to a fixed position in the call frame). In the function call stack frame structure, the addresses of each area in each stack frame gradually increase from the top of the stack (that is, the position pointed to by the stack pointer) to the bottom of the stack. For example, the address of the area storing the saved registers, local variables and temporary variables in the current frame is -4, the address of the area storing parameter 1 in the call frame is +4, the address of the area storing the return address is +8, and the addresses of the remaining areas are not shown. The call frame also includes areas for storing other parameters such as parameter n.

[0064] It should be noted that Figure 3This is just an example. With different CPU architectures, the function call stack frame structure will also be slightly different. When the stack is backtraced, the address of the current frame can be obtained by reading the frame pointer, and then the function return address, parameters, etc. can be obtained through the address offset. Based on the function return address, the call frame that calls the current frame can be obtained. Then, the frame pointer of the call frame can be used to obtain the frame address of the call frame, and so on until the entire call stack information is obtained.

[0065] Step 3: Alert the user-mode process.

[0066] This step sends the process PID, process name COMM, current handle number, and call stack information to the second user state process through netlink for subsequent data processing by the second user state process.

[0067] Specifically, the process PID, process name COMM, current handle number, and call stack information are encapsulated into a structure, and the sending function provided by the fd_netlink module is called to send the encapsulated structure to the second user state process to alert the user. After receiving the message, the second user state process can print or upload it to the upper platform for processing.

[0068] Figure 4 is a block diagram of a handle alarm device according to an exemplary embodiment of the present disclosure. The handle alarm device is applied to the kernel state of the operating system. Figure 4 The device includes an acquisition unit 401 and an alarm unit 402.

[0069] The acquisition unit 401 may acquire the current handle number before allocating a handle to the first user state process, wherein the current handle number indicates the number of handles already used by the first user state process.

[0070] The alarm unit 402 may send an alarm message to the second user state process when it is determined that the current number of handles exceeds an alarm threshold, wherein the alarm threshold is less than the maximum number of handles of the process.

[0071] Optionally, the alarm unit 402 may further: obtain process information of the first user state process; and send alarm information including the process information to the second user state process.

[0072] Optionally, the alarm unit 402 may also obtain a digital identifier, a name, a current number of handles, and call stack information of the first user-mode process as process information.

[0073] Optionally, the alarm unit 402 may further: obtain register information; and perform a stack backtrace operation on the function call stack frame structure according to the register information to obtain call stack information of the first user state process.

[0074] Optionally, the alarm unit 402 can also: determine the current frame from the function call stack frame structure according to the register information; determine the frame information of the current frame and the calling frame that calls the current frame; use the calling frame as the new current frame, and continue to execute the steps of determining the frame information of the current frame and the calling frame that calls the current frame until a new calling frame cannot be determined; use the frame information of each frame that has a calling relationship as the call stack information of the first user state process.

[0075] Optionally, the device further includes a connection unit (not shown in the figure) and a receiving unit (not shown in the figure). The connection unit can establish a two-way communication connection with the second user state process; the receiving unit can receive the alarm threshold sent by the second user state process based on the two-way communication connection.

[0076] According to an embodiment of the present disclosure, an electronic device may be provided. Figure 5 It is a block diagram of an electronic device 500 according to an embodiment of the present disclosure, and the electronic device includes at least one memory 501 and at least one processor 502, wherein the at least one memory stores a computer executable instruction set 5011 and an operating system 5012, and when the computer executable instruction set 5011 is executed by the at least one processor 502, the handle alarm method according to the embodiment of the present disclosure is executed.

[0077] As an example, the electronic device 500 may be a PC, a tablet device, a personal digital assistant, a smart phone, or other device capable of executing the above instruction set. Here, the electronic device 500 is not necessarily a single electronic device, but may also be any device or circuit collection capable of executing the above instructions (or instruction sets) individually or in combination. The electronic device 500 may also be part of an integrated control system or system manager, or may be configured as a portable electronic device interconnected with a local or remote (e.g., via wireless transmission) interface.

[0078] In the electronic device 500, the processor 502 may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller or a microprocessor. As an example and not a limitation, the processor 502 may also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, etc.

[0079] The processor 502 can execute instructions or codes stored in the memory, wherein the memory 501 can also store data. Instructions and data can also be sent and received over the network via the network interface device, wherein the network interface device can use any known transmission protocol.

[0080] The memory 501 may be integrated with the processor 502, for example, by placing RAM or flash memory within an integrated circuit microprocessor or the like. In addition, the memory 501 may include a separate device, such as an external disk drive, a storage array, or any other storage device that can be used by a database system. The memory 501 and the processor 502 may be operationally coupled, or may communicate with each other, such as through an I / O port, a network connection, etc., so that the processor 502 can read files stored in the memory 501.

[0081] In addition, the electronic device 500 may further include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, a mouse, a touch input device, etc.) All components of the electronic device may be connected to each other via a bus and / or a network.

[0082] According to an embodiment of the present disclosure, a computer-readable storage medium may also be provided, wherein when the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor is prompted to execute the handle alarm method of the embodiment of the present disclosure. Examples of computer-readable storage media here include: read-only memory (ROM), random access programmable read-only memory (PROM), electrically erasable programmable read-only memory (EEPROM), random access memory (RAM), dynamic random access memory (DRAM), static random access memory (SRAM), flash memory, non-volatile memory, CD-ROM, CD-R, CD+R, CD-RW, CD+RW, DVD-ROM, DVD-R, DVD+R, DVD-RW, DVD+RW, DVD-RAM, BD-ROM, BD-R, BD-R LTH, BD-RE, Blu-ray or optical disk storage, hard disk drive (HDD), solid state drive (SSD), card storage (such as, multimedia card, secure digital (SD) card or extreme digital (XD) card), magnetic tape, floppy disk, magneto-optical data storage device, optical data storage device, hard disk, solid state disk and any other device, any other device is configured to store computer programs and any associated data, data files and data structures in a non-transitory manner and provide the computer programs and any associated data, data files and data structures to a processor or computer so that the processor or computer can execute the computer program. The computer program in the above-mentioned computer-readable storage medium can be run in an environment deployed in a computer device such as a client, a host, an agent device, a server, etc. In addition, in one example, the computer program and any associated data, data files and data structures are distributed on a networked computer system, so that the computer program and any associated data, data files and data structures are stored, accessed and executed in a distributed manner by one or more processors or computers.

[0083] According to an embodiment of the present disclosure, a computer program product is provided, including computer instructions, and when the computer instructions are executed by a processor, the handle alarm method of the embodiment of the present disclosure is implemented.

[0084] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the appended claims.

[0085] It should be understood that the present disclosure is not limited to the exact structures that have 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 disclosure is limited only by the appended claims.

Claims

1. A handle alarm method, characterized in that: Applied to the kernel state of the operating system, the handle alarm method includes: Before allocating a handle to the first user state process, obtaining a current handle number, wherein the current handle number indicates the number of handles already used by the first user state process; When it is determined that the current number of handles exceeds an alarm threshold, process information of the first user state process is obtained, and alarm information including the process information is sent to a second user state process, wherein the alarm threshold is less than a maximum number of process handles.

2. The handle alarm method according to claim 1, characterized in that: The obtaining process information of the first user state process includes: Obtain a digital identifier, a name, the current number of handles, and call stack information of the first user state process as the process information.

3. The handle alarm method according to claim 2, characterized in that: The operation of obtaining the call stack information of the first user state process includes: Get register information; According to the register information, a stack backtrace operation is performed on the function call stack frame structure to obtain the call stack information of the first user state process.

4. The handle alarm method according to claim 3, characterized in that: The performing a stack backtracking operation on a function call stack frame structure according to the register information to obtain the call stack information of the first user state process includes: Determine a current frame from the function call stack frame structure according to the register information; Determine frame information of the current frame and a calling frame that calls the current frame; Taking the calling frame as a new current frame, and continuing to perform the steps of determining the frame information of the current frame and calling the calling frame of the current frame until a new calling frame cannot be determined; The frame information of each frame with a determined calling relationship is used as the call stack information of the first user state process.

5. The handle alarm method according to any one of claims 1 to 4, characterized in that: The handle alarm method also includes: Establishing a bidirectional communication connection with the second user state process; Based on the bidirectional communication connection, the alarm threshold sent by the second user state process is received.

6. A handle alarm device, characterized in that: Applied to the kernel state of the operating system, the handle alarm device includes: An acquiring unit is configured to acquire a current handle number before allocating a handle to the first user state process, wherein the current handle number indicates the number of handles already used by the first user state process; The alarm unit is configured to obtain process information of the first user state process and send alarm information containing the process information to the second user state process when it is determined that the current number of handles exceeds an alarm threshold, wherein the alarm threshold is less than the maximum number of process handles.

7. An electronic device, characterized in that: include: at least one processor; at least one memory storing computer executable instructions, Wherein, when the computer executable instructions are executed by the at least one processor, the at least one processor is prompted to execute the handle alarm method as claimed in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by at least one processor, the at least one processor is prompted to perform the handle alarm method according to any one of claims 1 to 5.

9. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by at least one processor, the at least one processor is prompted to execute the handle alarm method according to any one of claims 1 to 5.