CN115905137A - File descriptor leakage monitoring method, device, equipment and storage medium - Google Patents

File descriptor leakage monitoring method, device, equipment and storage medium Download PDF

Info

Publication number
CN115905137A
CN115905137A CN202111162046.XA CN202111162046A CN115905137A CN 115905137 A CN115905137 A CN 115905137A CN 202111162046 A CN202111162046 A CN 202111162046A CN 115905137 A CN115905137 A CN 115905137A
Authority
CN
China
Prior art keywords
target process
mode
file descriptor
target
function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111162046.XA
Other languages
Chinese (zh)
Inventor
方彦彬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Rockwell Technology Co Ltd
Original Assignee
Beijing Rockwell Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Rockwell Technology Co Ltd filed Critical Beijing Rockwell Technology Co Ltd
Priority to CN202111162046.XA priority Critical patent/CN115905137A/en
Publication of CN115905137A publication Critical patent/CN115905137A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the application provides a method, a device, equipment and a storage medium for monitoring file descriptor leakage. In the embodiment of the application, a file descriptor leakage monitoring operation can be performed on a process to be monitored, the number of file descriptors occupied by the file operation performed by the current monitored process is obtained, and under the condition that the number of the file descriptors exceeds a preset threshold value of file descriptor leakage, corresponding call stack information in the process of performing the file operation by the current monitored process is obtained according to a specific call mode corresponding to the current monitored process, so that comprehensive call stack information is obtained. Based on the method, the reason for the leakage of the file descriptor of the current monitored process can be accurately analyzed.

Description

File descriptor leakage monitoring method, device, equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for monitoring disclosure of a file descriptor.
Background
In the Linux operating system, in order to efficiently manage the process to perform opening or closing operations on files, a kernel uses a File Descriptor (fd) as an index to uniquely identify files that have been opened. When a process opens a file, the system allocates an fd to the process, and the fd can be used by the process to access the corresponding file; when a process closes an opened file, the system releases its corresponding fd so that the next time the process opens the file, there is an available fd.
In actual use, the fd that the system allows a process to occupy has an upper limit value, for example, generally 1024, and if the number of files opened by the process is large or the corresponding fd is not released in time after the files are closed, which results in an insufficient number of available fds, the system may report an error, or even cause an application program to which the process belongs to crash, which causes the application program to be forcibly exited during the operation process, and affects the stability of the operation of the application program, which is called fd leakage.
In the prior art, call stack information generated when a process executes a file operation is usually tracked, and the reason for fd leakage is analyzed according to the call stack information. However, in an actual application scenario, the acquired call stack information is not comprehensive, and the reason for fd leakage based on the analysis is not accurate enough.
Disclosure of Invention
Various aspects of the present application provide a method, an apparatus, a device, and a storage medium for monitoring disclosure of a file descriptor, so as to obtain call stack information corresponding to a process execution file operation according to a specific call mode corresponding to the process, to obtain comprehensive call stack information, and to accurately analyze a reason for disclosure of the file descriptor.
The embodiment of the application provides a method for monitoring leakage of a file descriptor, which comprises the following steps: acquiring a target process to be monitored; registering a target function and a corresponding identification signal for the target process in a system, wherein the target function is used for generating first call stack information for the target process in a user mode call mode; and if the number of the file descriptors occupied by the target process is greater than a preset threshold and the calling mode of the target process is a user mode calling mode, sending the identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
In an optional embodiment, before determining whether the number of file descriptors occupied by the target process is greater than a preset threshold, the method further includes: and periodically counting the number of the file descriptors occupied by the target process according to a set monitoring period in the process of executing the file operation by the target process.
In an optional embodiment, further comprising: respectively adding a monitoring state enabling mark in a file descriptor applying function and a file descriptor releasing function in a system, and initializing the monitoring state enabling mark to be in a non-enabling state; and setting the monitoring state enabling flag to be in an enabling state under the condition that the number is larger than a preset threshold value so as to allow file descriptor leakage monitoring operation to be executed aiming at the target process.
In an optional embodiment, further comprising: and resetting the monitoring state enabling mark to be in a non-enabling state under the condition that the number is changed from being larger than a preset threshold value to being smaller than or equal to the preset threshold value.
In an optional embodiment, the calling mode for the target process further includes a kernel-mode calling mode, and the method further includes: and if the number is larger than a preset threshold value and the calling mode of the target process is a kernel mode calling mode, acquiring second calling stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
In an optional embodiment, before obtaining second call stack information generated when the target process executes the file descriptor applying function and the file descriptor releasing function in the kernel-mode calling mode, the method further includes: if the monitoring state enabling mark is in an enabling state, judging whether the current process for executing the file descriptor applying function and the file descriptor releasing function is a target process; if so, judging whether the current calling mode of the target process is a kernel mode calling mode, and if so, executing operation of acquiring second calling stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
In an optional embodiment, further comprising: in the event that the target process is released, the target function and identification signal are logged off of the system.
In an optional embodiment, further comprising: and analyzing the reason for causing the leakage of the file descriptor of the target process according to the first call stack information and/or the second call stack information.
Embodiments of the present application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to implement the steps in the method embodiments.
In the embodiment of the application, a file descriptor disclosure monitoring operation can be performed on a process to be monitored, the number of file descriptors occupied by the currently monitored process for performing the file operation is acquired, and corresponding call stack information in the process of performing the file operation by the currently monitored process is acquired according to a specific call mode corresponding to the currently monitored process under the condition that the number of the file descriptors exceeds a preset threshold value for disclosure of the file descriptors, so that comprehensive call stack information is acquired. Based on the method, the reason for the leakage of the file descriptor of the current monitored process can be accurately analyzed.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a flowchart of a method for monitoring disclosure of a file descriptor according to an embodiment of the present disclosure;
fig. 2 is a schematic structural diagram of a file descriptor disclosure monitoring device according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a file descriptor leakage monitoring apparatus according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
In Linux or Unix operating systems, everything can be regarded as a file, for example, a normal file, a directory, a link, and a device are regarded as one file. The kernel accesses the File by using a File Descriptor (fd), and each time an application opens or creates a File, the kernel returns a nonnegative integer as the File Descriptor corresponding to the File, so that the File to be read and written can be specified according to the File Descriptor returned by the kernel when the File is read and written. It is to be appreciated that the file descriptor is a non-negative integer index that the kernel creates to efficiently manage files opened by a process.
However, the number of file descriptors is limited, and the number of file descriptors that can be occupied in the system is related to the size of the system memory, which is affected by the hardware performance. Therefore, after the file call is finished, the corresponding file descriptor needs to be closed, so that the number corresponding to the file descriptor is recycled by the system and reused when the file is opened or created next time. If the corresponding file descriptor is not closed in time after the file call is finished, the file descriptor is insufficient, so that the application program cannot open or create a new file, the operation of the system is influenced, and even the system is crashed. In general, a phenomenon that such a file is not closed in time but continuously occupies a file descriptor is called file descriptor leakage.
The embodiment of the application provides a method for monitoring leakage of a file descriptor, which is used for monitoring an execution process, and acquiring call stack information corresponding to file operation executed by a current monitored process according to a specific call mode corresponding to the current monitored process under the condition that the current monitored process is determined to have a risk of leakage of the file descriptor or the leakage of the file descriptor is determined, so as to analyze the reason of leakage of the file descriptor according to the call stack information.
Fig. 1 is a flowchart of a file descriptor leakage monitoring method according to an embodiment of the present application, and as shown in fig. 1, the method includes:
s1, acquiring a target process to be monitored;
s2, registering a target function and a corresponding identification signal for the target process in the system, wherein the target function is used for generating first call stack information for the target process in a user mode call mode;
and S3, if the number of the file descriptors occupied by the target process is larger than a preset threshold value and the calling mode of the target process is a user mode calling mode, sending an identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
In this embodiment of the present application, a file descriptor leakage monitoring operation may be performed on a designated process according to a service requirement, and a file descriptor leakage monitoring operation may also be performed on all processes in the system, which is not limited herein. Further, in the case that the monitored process is a designated process, the monitored process may be a process for executing a main service function, or may be a process with a higher execution frequency, which is not limited herein. Based on this, in the case that file descriptor leakage monitoring needs to be performed, a process identifier that needs to monitor whether there is a risk of file descriptor leakage may be obtained, and optionally, a monitoring request initiated by a user state or a kernel state may be received, where the request may include the process identifier that needs to be monitored.
Under the condition of acquiring a process identifier required to be monitored, a target process to be monitored can be determined according to the process identifier, and a target function and an identifier signal corresponding to the target function are registered for the target process in the system. Because the process does not generate corresponding call stack information in the process of executing file opening or closing operation in the user mode, the target function in the embodiment of the application is used for generating corresponding first call stack information for the target process in the user mode, so that under the condition that the risk of file descriptor leakage in the target process is determined, leakage points possibly causing file descriptor leakage in the file executing operation process of the target process are located by using the first call stack information generated by the target function. Further optionally, the target function and the identification signal may also be logged off from the system in case the target process is released.
Because each process has its corresponding file descriptor list, all files currently opened by the corresponding process are recorded in the file descriptor list, and each file corresponds to one file descriptor. Based on this, under the condition that the file descriptor leakage monitoring is determined to be performed on the target process, the number of the file descriptors occupied by the target process can be counted according to the set monitoring time period in the file operation process performed by the target process, and whether the risk of file descriptor leakage exists in the target process or the file descriptor leakage occurs is determined according to the counted number. Optionally, a corresponding preset threshold may be set for each process to be monitored, where the preset threshold may be used to measure whether there is a risk of file descriptor leakage in the currently monitored process, or to measure whether a file descriptor leakage has occurred in the currently monitored process.
For example, the number of file descriptors allowed to be occupied by a process is usually 1024 at most, and if the number of file descriptors currently occupied by the process exceeds 600, which may be considered that a file descriptor leakage risk occurs, a preset threshold may be set to 600, so as to measure whether a currently monitored process has a file descriptor leakage risk; if the number of the file descriptors currently occupied by the process exceeds 800, which may be regarded as that the file descriptor leakage has occurred, a preset threshold may be set to 800, which is used to measure whether the file descriptor leakage has occurred in the currently monitored process. The setting mode of the preset threshold is not limited herein, and can be determined according to actual requirements; in addition, specific values of the preset threshold are not limited, and the above description is only an exemplary description, and is not limited thereto.
Further, under the condition that the number of the file descriptors occupied by the target process is obtained, the obtained number of the file descriptors can be compared with a preset threshold, under the condition that the number of the file descriptors is larger than the preset threshold and the calling mode of the target process is a user mode calling mode, an identification signal registered in the system can be sent to the target process to control the target process to execute a target function corresponding to the identification signal according to the signal identification, calling stack information corresponding to file operation executed by the target process is generated, further, first calling stack information generated by the target function returned by the target process can be received, the reason that the file descriptors are leaked when the target process executes file operation within a set monitoring period is analyzed according to the received first calling stack information, and corresponding processing is carried out, and the problem of file descriptor leakage is solved.
In an optional embodiment of the present application, in a case that the file descriptor leakage monitoring needs to be executed, monitoring state enabling flags may be further added to a file descriptor applying function and a file descriptor releasing function in the system, respectively, so as to flexibly start or end a file descriptor leakage monitoring operation for each process according to a monitoring requirement of each process. Alternatively, in the case where the monitoring state enable flag is added, the monitoring state enable flag may be initialized to a non-enabled state, indicating that the file descriptor leak monitoring operation is not started by default. Further, in the case that it is determined that the number of the file descriptors occupied by the target process is greater than the preset threshold, the monitoring state enable flag may be set to an enable state, so as to allow the file descriptor disclosure monitoring operation to be performed on the target process.
In the embodiment of the present application, the implementation form of the monitoring state enabling flag is not limited. For example, the monitoring state enabling flag may be of a numerical type, and may alternatively represent a non-enabled state in a case where the value of the monitoring state enabling flag is 0; in the case where the value of the monitoring state enable flag is 1, it can be expressed as an enable state. For another example, the monitoring state enabling flag may be of a boolean type, and optionally, in the case that the value of the monitoring state enabling flag is false, may be represented as a non-enabled state; in the case where the value of the monitoring state enable flag is true, it can be expressed as an enable state. For another example, the monitoring state enabling flag may also be a character type, and optionally, in the case that the value of the monitoring state enabling flag is 'N', it may be represented as a non-enabled state; in the case where the value of the monitoring state enable flag is 'Y', it can be expressed as an enable state. Which type and corresponding specific value are specifically adopted can be determined according to actual requirements, and the above description is only an exemplary description.
Based on this, in the case that the monitoring state enabling flag is in an enabling state, in the file operation process executed by the target process, the number of the file descriptors occupied by the target process may be periodically counted according to the setting monitoring, and in the case that it is determined that the number of the file descriptors is greater than the preset threshold, the call stack information corresponding to the target process is obtained, and the number of the file descriptors occupied by the target process is continuously monitored. Further, when the number of the file descriptors occupied by the target process is monitored to be changed from being greater than the preset threshold to being smaller than or equal to the preset threshold, it is indicated that the target process does not have the risk of file descriptor leakage, and at this time, the monitoring state enabling flag may be reset to the non-enabling state, so as to end the file descriptor leakage monitoring operation performed on the target process.
In practical application, in the process of executing file operation in a preset time period, the invoked mode may be a user mode invoking mode, a kernel mode invoking mode, or both the user mode invoking mode and the kernel mode invoking mode in the preset time period; for example, the preset period is 5 minutes, and the target process is called by the user mode in the first 2 minutes and by the kernel mode in the last 3 minutes. In the kernel mode, when the process executes the file operation, the system automatically generates call stack information corresponding to the process according to the executed processes of the file descriptor application function and the file descriptor release function.
Based on this, in the optional embodiment of the present application, in the process of performing the monitoring operation on the target process within the set monitoring period, if the calling mode for the target process further includes a kernel mode calling mode, under the condition that it is determined that the number of the file descriptors occupied by the target process is greater than the preset threshold and the calling mode for the target process is the kernel mode calling mode, second call stack information generated when the target process performs the file descriptor application function and the file descriptor release function in the kernel mode calling mode may be obtained, and according to the first call stack information and the second call stack information within the set monitoring period, a reason why the file descriptor is leaked when the target process performs the file operation within the set monitoring period is analyzed, so as to perform processing, and solve the problem of the file descriptor leakage.
In an optional embodiment of the present application, before obtaining the call stack information, it may further be determined whether the monitoring state enable flag is in an enable state; if yes, the process needing to be monitored is judged, and whether the process currently executing the file descriptor application function and the file descriptor release function is the target process is further judged. Optionally, a process identifier of the currently executed file descriptor application function and the file descriptor release function may be obtained, and if it is determined that the process of the currently executed file descriptor application function and the file descriptor release function is the target process, call stack information corresponding to the target process is obtained according to comparison between the process identifier and the target process identifier.
Since the process executes the file operation in the user mode and does not generate the corresponding call stack information, and the process generates the corresponding call stack information in the kernel mode, before the call stack information corresponding to the target process is acquired, the specific mode for acquiring the call stack information needs to be determined according to the call mode corresponding to the target process. Optionally, if the current calling mode of the target process is judged to be a kernel mode calling mode, executing an operation of acquiring second call stack information generated when the target process executes a file descriptor application function and a file descriptor release function in the kernel mode calling mode; if the current calling mode for the target process is judged to be the user mode calling mode, the first call stack information generated by the target function corresponding to the target process is obtained according to the mode in the embodiment.
Further, under the condition that the call stack information corresponding to the target process is obtained, the obtained call stack information can be output to equipment corresponding to system maintenance personnel, so that the system maintenance personnel can determine which files are opened and closed by the target process in a set monitoring period according to the call stack information, and therefore which files are opened all the time, and codes for executing operations on the files which are not closed can be the reason for leaking the file descriptors. Based on the method, the related codes can be checked, the specific reason causing the leakage of the file descriptor is determined and modified, and the system breakdown or the stability of the operation of the application program is prevented from being influenced.
In the embodiment of the present application, the implementation form of the device corresponding to the system maintainer is not limited, and in an optional embodiment, the device corresponding to the system maintainer may be a computer device or a terminal device; optionally, the terminal device may be a smart device such as a mobile phone or a tablet computer. Further optionally, in the case of acquiring the call stack information corresponding to the first process, the files that are always opened may be determined according to the call stack information, and the first process is controlled to stop operating the files, so as to ensure the security of the system and the stability of the application program. Of course, other operations may also be executed according to the obtained call stack information, which is not limited herein, and the above is only an exemplary description.
In the embodiment of the application, a file descriptor leakage monitoring operation can be periodically executed on a process to be monitored within a set monitoring period, the number of file descriptors occupied by the file operation executed by the current monitored process is acquired, and corresponding call stack information in the process of executing the file operation by the current monitored process in a user mode call mode and/or a kernel mode call mode is acquired according to a specific call mode corresponding to the current monitored process under the condition that the number of the file descriptors exceeds a preset threshold value which may cause the file descriptor leakage, so that comprehensive call stack information is acquired. Based on the method, the reason of the file descriptor generated by the current monitored process in the set monitoring time period can be accurately analyzed.
For specific details of the implementation process of the method, reference may be made to the above system method embodiment, which is not described herein again. It should be noted that the execution subjects of the steps of the methods provided in the above embodiments may be the same device, or different devices may be used as the execution subjects of the methods. For example, the execution subjects of steps S1 to S3 may be device a; for another example, the execution subject of steps S1 to S2 may be device a, and the execution subject of step S3 may be device B; and so on.
In addition, in some of the flows described in the above embodiments and the drawings, a plurality of operations occurring in a specific order are included, but it should be clearly understood that these operations may be executed out of the order they appear herein or in parallel, and the order of the operations, such as S1, S2, etc., is merely used to distinguish various operations, and the order itself does not represent any order of execution. Additionally, the flows may include more or fewer operations, and the operations may be performed sequentially or in parallel. It should be noted that, the descriptions of "first", "second", etc. in this document are used for distinguishing different messages, devices, modules, etc., and do not represent a sequential order, nor limit the types of "first" and "second" to be different.
An embodiment of the present application further provides a device for monitoring leakage of a file descriptor, fig. 2 is a schematic structural diagram of the device for monitoring leakage of a file descriptor in an embodiment of the present application, and as shown in fig. 2, the device for monitoring leakage of a file descriptor includes: a processor 21 and a memory 22 in which computer programs are stored. The processor 21 and the memory 22 may be one or more. The memory 22 is mainly used for storing computer programs, and these computer programs can be executed by the processor, so that the processor controls the file descriptor leakage monitoring device to implement corresponding functions and complete corresponding actions or tasks. In addition to storing computer programs, the memory may be configured to store other various data to support operations on the file descriptor leakage monitoring device, examples of which include instructions for any application or method operating on the file descriptor leakage monitoring device.
The memory 22, which may be implemented by any type or combination of volatile or non-volatile memory devices, such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
In the embodiment of the present application, the implementation form of the processor 21 is not limited, and may be, for example, but not limited to, a CPU, a GPU, an MCU, or the like. The processor 21 may be seen as a control system of the file descriptor leakage monitoring device and may be adapted to execute a computer program stored in the memory 22 to control the file descriptor leakage monitoring device to perform a corresponding function, to perform a corresponding action or task. It is worth noting that the functions, actions or tasks to be realized are different according to the different implementation forms and scenes of the file descriptor leakage monitoring equipment; accordingly, the computer programs stored in the memory 22 may be different, and the execution of different computer programs by the processor 21 may control the file descriptor leakage monitoring device to perform different functions, perform different actions or tasks.
In some optional embodiments, as shown in fig. 2, the file descriptor disclosure monitoring apparatus may further include: communication components 23, a display 24, and power components 25. Only some components are schematically shown in fig. 2, which does not mean that the file descriptor disclosure monitoring apparatus includes only the components shown in fig. 2, and the file descriptor disclosure monitoring apparatus may further include other components according to different application requirements, specifically depending on the product form of the file descriptor disclosure monitoring apparatus.
In the embodiment of the present application, a use scenario and an implementation form of the file descriptor leakage monitoring device are not limited, and in different use scenarios, the implementation form of the file descriptor leakage monitoring device may also be different, for example, in a vehicle use scenario, an on-vehicle device in a vehicle may have multiple processes, each process needs to open a corresponding file when a specific task is executed, and for example, when a process needs to display a picture, a picture file may be opened for display. Accordingly, in this scenario, the file descriptor leakage monitoring device may be one of the vehicle-mounted devices, and may perform the file descriptor leakage monitoring operation on the process running by itself, or may perform the file descriptor leakage monitoring operation on other vehicle-mounted devices on the vehicle, which is not limited herein.
In an embodiment of the application, the processor 21, when executing the computer program in the memory 22, is configured to: acquiring a target process to be monitored; registering a target function and a corresponding identification signal for a target process in a system, wherein the target function is used for generating first call stack information for the target process in a user mode call mode; and if the number of the file descriptors occupied by the target process is larger than a preset threshold value and the calling mode of the target process is a user mode calling mode, sending the identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
In an optional embodiment, before determining whether the number of file descriptors occupied by the target process is greater than the preset threshold, the processor 21 is further configured to: and in the process of executing the file operation by the target process, periodically counting the number of file descriptors occupied by the target process according to a set monitoring period.
In an optional embodiment, the processor 21 is further configured to: respectively adding a monitoring state enabling mark in a file descriptor applying function and a file descriptor releasing function in the system, and initializing the monitoring state enabling mark into a non-enabling state; and setting the monitoring state enabling flag to be in an enabling state under the condition that the number is larger than the preset threshold value so as to allow the file descriptor leakage monitoring operation to be executed aiming at the target process.
In an alternative embodiment, the processor 21 is further configured to: and resetting the monitoring state enabling flag to be in a non-enabling state under the condition that the number is changed from being larger than the preset threshold value to being smaller than or equal to the preset threshold value.
In an optional embodiment, the calling mode for the target process further includes a kernel mode calling mode, and if the number is greater than the preset threshold and the calling mode for the target process is the kernel mode calling mode, the processor 21 is further configured to obtain second call stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
In an optional embodiment, before obtaining the second call stack information generated when the target process executes the file descriptor applying function and the file descriptor releasing function in the kernel-mode calling mode, the processor 21 is further configured to: if the monitoring state enabling mark is an enabling state, judging whether the process of currently executing the file descriptor application function and the file descriptor release function is a target process; if so, judging whether the current calling mode of the target process is a kernel mode calling mode, and if so, executing the operation of acquiring second call stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
In an optional embodiment, the processor 21 is further configured to: in the event that the target process is released, the target function and the identification signal are logged off the system.
In an alternative embodiment, the processor 21 is further configured to: and analyzing the reason of the leakage of the file descriptor of the target process according to the first call stack information and/or the second call stack information.
Correspondingly, the embodiment of the present application further provides a computer-readable storage medium storing a computer program, where the computer program is capable of implementing each step that can be performed by the file descriptor leakage monitoring device in the foregoing method embodiments when executed.
The embodiment of the application also provides a device for monitoring the leakage of the file descriptor. For example, the processing device may be implemented as a virtual device, such as an application program, in a Communication Control Unit (CCU). As shown in fig. 3, the file descriptor leakage monitoring apparatus includes:
the acquisition module 301: the method comprises the steps of obtaining a target process to be monitored;
the first processing module 302: the system comprises a target function and a corresponding identification signal, wherein the target function is used for registering a target process in the system and generating first call stack information for the target process in a user mode call mode;
the second processing module 302: and if the number of the file descriptors occupied by the target process is greater than the preset threshold and the calling mode of the target process is a user mode calling mode, sending an identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
In an optional embodiment, before determining whether the number of file descriptors occupied by the target process is greater than a preset threshold, the second processing module 302 is further configured to: and in the process of executing the file operation by the target process, periodically counting the number of file descriptors occupied by the target process according to a set monitoring period.
In an alternative embodiment, the second processing module 302 is further configured to: respectively adding a monitoring state enabling mark in a file descriptor applying function and a file descriptor releasing function in a system, and initializing the monitoring state enabling mark into a non-enabling state; and setting the monitoring state enabling flag to be in an enabling state under the condition that the number is larger than the preset threshold value so as to allow the file descriptor leakage monitoring operation to be executed aiming at the target process.
In an alternative embodiment, the second processing module 302 is further configured to: and resetting the monitoring state enabling flag to be in a non-enabling state under the condition that the number is changed from being larger than the preset threshold value to being smaller than or equal to the preset threshold value.
In an optional embodiment, the calling manner for the target process further includes a kernel-mode calling manner, and if the number is greater than the preset threshold and the calling manner for the target process is the kernel-mode calling manner, the second processing module 302 is further configured to obtain second call stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel-mode calling manner.
In an optional embodiment, before acquiring the second call stack information generated when the target process executes the file descriptor applying function and the file descriptor releasing function in the kernel-state calling mode, the second processing module 302 is further configured to: if the monitoring state enabling mark is an enabling state, judging whether the process of currently executing the file descriptor application function and the file descriptor release function is a target process; if so, judging whether the current calling mode of the target process is a kernel mode calling mode, and if so, executing the operation of acquiring second call stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
In an alternative embodiment, the second processing module 302 is further configured to: in case the target process is released, the target function and the identification signal are logged off from the system.
In an alternative embodiment, the second processing module 302 is further configured to: and analyzing the reason for the leakage of the file descriptor of the target process according to the first call stack information and/or the second call stack information.
The communication component in the above embodiments is configured to facilitate communication between the device in which the communication component is located and other devices in a wired or wireless manner. The device where the communication component is located can access a wireless network based on a communication standard, such as WiFi, a mobile communication network such as 2G, 3G, 4G/LTE, 5G, or the like, or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component further comprises a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra Wideband (UWB) technology, bluetooth (BT) technology, and other technologies.
The display in the above embodiments includes a screen, which may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
The power supply assembly of the above embodiments provides power to various components of the device in which the power supply assembly is located. The power components may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the device in which the power component is located.
The audio component in the above embodiments may be configured to output and/or input an audio signal. For example, the audio component includes a Microphone (MIC) configured to receive an external audio signal when the device in which the audio component is located is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal may further be stored in a memory or transmitted via a communication component. In some embodiments, the audio assembly further comprises a speaker for outputting audio signals.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Disks (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of other like elements in a process, method, article, or apparatus comprising the element.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art to which the present application pertains. Any modification, equivalent replacement, improvement or the like made within the spirit and principle of the present application shall be included in the scope of the claims of the present application.

Claims (10)

1. A file descriptor leakage monitoring method is characterized by comprising the following steps:
acquiring a target process to be monitored;
registering a target function and a corresponding identification signal for the target process in the system, wherein the target function is used for generating first call stack information for the target process in a user mode call mode;
and if the number of the file descriptors occupied by the target process is larger than a preset threshold value and the calling mode of the target process is a user mode calling mode, sending the identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
2. The method of claim 1, further comprising:
respectively adding a monitoring state enabling mark in a file descriptor applying function and a file descriptor releasing function in a system, and initializing the monitoring state enabling mark to be in a non-enabling state; and
and setting the monitoring state enabling flag to be in an enabling state under the condition that the number is larger than a preset threshold value, so as to allow the file descriptor leakage monitoring operation to be executed aiming at the target process.
3. The method of claim 2, further comprising:
and resetting the monitoring state enabling flag to be in a non-enabling state under the condition that the number is changed from being larger than a preset threshold value to being smaller than or equal to the preset threshold value.
4. The method of claim 2 or 3, wherein the calling modality for the target process further comprises a kernel-mode calling modality, the method further comprising:
and if the number is larger than a preset threshold value and the calling mode of the target process is a kernel mode calling mode, acquiring second calling stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
5. The method according to claim 4, before acquiring second call stack information generated when the target process executes the file descriptor application function and the file descriptor release function in a kernel-mode call mode, further comprising:
if the monitoring state enabling mark is in an enabling state, judging whether the current process for executing the file descriptor applying function and the file descriptor releasing function is a target process;
if so, judging whether the current calling mode of the target process is a kernel mode calling mode, and if so, executing operation of acquiring second calling stack information generated when the target process executes the file descriptor application function and the file descriptor release function in the kernel mode calling mode.
6. The method of any one of claims 1-5, further comprising:
in the event that the target process is released, the target function and identification signal are logged off of the system.
7. The method of any one of claims 1-5, further comprising:
and analyzing the reason for causing the leakage of the file descriptor of the target process according to the first call stack information and/or the second call stack information.
8. A file descriptor leakage monitoring apparatus, comprising:
an acquisition module: the method comprises the steps of obtaining a target process to be monitored;
a first processing module: the system is used for registering a target function and a corresponding identification signal for the target process in the system, wherein the target function is used for generating first call stack information for the target process in a user mode;
a second processing module: and if the number of the file descriptors occupied by the target process is greater than a preset threshold and the calling mode of the target process is a user mode calling mode, sending the identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
9. A file descriptor leakage monitoring apparatus, comprising: a processor and a memory storing a computer program;
the processor to execute the computer program to:
acquiring a target process to be monitored;
registering a target function and a corresponding identification signal for the target process in a system, wherein the target function is used for generating first call stack information for the target process in a user mode call mode;
and if the number of the file descriptors occupied by the target process is greater than a preset threshold and the calling mode of the target process is a user mode calling mode, sending the identification signal to the target process so as to control the target process to execute the target function and return first calling stack information generated by the target function.
10. A computer-readable storage medium storing a computer program, wherein the computer program, when executed, performs the steps of the method of any one of claims 1-8.
CN202111162046.XA 2021-09-30 2021-09-30 File descriptor leakage monitoring method, device, equipment and storage medium Pending CN115905137A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111162046.XA CN115905137A (en) 2021-09-30 2021-09-30 File descriptor leakage monitoring method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111162046.XA CN115905137A (en) 2021-09-30 2021-09-30 File descriptor leakage monitoring method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115905137A true CN115905137A (en) 2023-04-04

Family

ID=86482833

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111162046.XA Pending CN115905137A (en) 2021-09-30 2021-09-30 File descriptor leakage monitoring method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115905137A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117195204A (en) * 2023-11-01 2023-12-08 建信金融科技有限责任公司 Abnormal data detection method, device, electronic equipment and computer readable medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117195204A (en) * 2023-11-01 2023-12-08 建信金融科技有限责任公司 Abnormal data detection method, device, electronic equipment and computer readable medium
CN117195204B (en) * 2023-11-01 2024-02-13 建信金融科技有限责任公司 Abnormal data detection method, device, electronic equipment and computer readable medium

Similar Documents

Publication Publication Date Title
CN107038107B (en) Method and device for acquiring application blocking information
CN106681811B (en) Multithreading scheduling method and device based on thread pool
CN107948744B (en) Interface detection method, interface detection device, and computer-readable storage medium
CN107645546B (en) File monitoring method based on android system, intelligent device and storage medium
CN111858112B (en) Method, client and server for detecting memory leakage
CN111625383B (en) Process exception event processing method and device, electronic equipment and storage medium
CN111143100A (en) Memory leak detection method, device, equipment and storage medium
CN111258847B (en) File handle monitoring and analyzing method, device, medium and equipment
CN112445686A (en) Memory leak detection method, device and computer-readable storage medium
CN115185777A (en) Abnormity detection method and device, readable storage medium and electronic equipment
CN115905137A (en) File descriptor leakage monitoring method, device, equipment and storage medium
CN109815695A (en) Detection method, device and the equipment of process safety
US20240152439A1 (en) Detection Method and Electronic Device
CN114356434A (en) Page loading method, equipment, device, storage medium and program product
CN104063288A (en) Process management method and device
CN112989323B (en) Process detection method, device, terminal and storage medium
CN112241362A (en) Test method, test device, server and storage medium
CN110069922A (en) A kind of system interface kidnaps detection method, device and terminal
CN113806183A (en) Application morton processing method, device, equipment, storage medium and program product
CN113485846A (en) Memory processing method and device
CN110888822A (en) Memory processing method, device and storage medium
CN117667604B (en) Data monitoring method, device, electronic equipment and storage medium for tracking event
CN110968516A (en) Application memory testing method and device and computer storage medium
CN112732568B (en) System log acquisition method and device, storage medium and terminal
CN104850551A (en) Data processing method, data processing apparatus and mobile terminal

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination