A process data acquisition method and device, electronic equipment and storage medium
By allocating a unique inode to each process in a preset file system and recording process descriptor information and metadata addresses, the problems of PID contention and metadata acquisition in Linux systems are solved, achieving efficient and reliable process management and control.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NEW H3C TECH CO LTD
- Filing Date
- 2026-03-04
- Publication Date
- 2026-07-21
AI Technical Summary
In Linux systems, PID contention issues lead to abnormal inter-process communication. The existing PIDFD mechanism cannot effectively obtain process metadata, increasing system call overhead and implementation complexity, especially in containerized environments.
By assigning a unique inode to each process in the preset file system, recording process descriptor information and metadata addresses, and using the statx function to obtain process metadata, frequent calls to other system interfaces are avoided.
It reduces system call overhead and implementation complexity, improves the efficiency of process metadata acquisition, enhances the accuracy of process control and monitoring, reduces the risk of memory fragmentation, and improves system performance and reliability.
Smart Images

Figure CN121785875B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for acquiring process data. Background Technology
[0002] In Linux (an operating system), process IDs (PIDs) are recycled and reused. When a process exits, its released PID may be reassigned to another new process, causing PID contention and potentially leading to inter-process communication errors. For example, process A might send data to process B based on process B's PID. However, if process B exits before process A sends the data, and process B's PID has been reassigned to a new process C, process A might mistakenly send the data to process C, potentially forcing process C to exit.
[0003] To avoid the aforementioned problems, the Linux system introduced the PIDFD (PID Descriptors) mechanism. This mechanism creates anonymous files based on the anonymous file mechanism, assigns file descriptors to these anonymous files, and establishes an association between processes and these anonymous files, allowing the file descriptors of anonymous files to represent processes. These anonymous file descriptors are called PIDFDs. This method leverages file system characteristics to ensure the global uniqueness of PIDFDs, and the PIDFD will not be assigned to other new processes after a process exits. Therefore, using PIDFD instead of PID avoids PID contention issues.
[0004] PIDFD is implemented based on the anonymous file mechanism. Although each file has a corresponding inode in the kernel, the inode only records basic file attributes. User space cannot obtain process metadata (such as runtime, resource usage, etc.) based on the inode corresponding to PIDFD. This causes user space to need to use procfs (Process Filesystem) or other system interfaces to obtain process metadata, thus increasing system call overhead and implementation complexity. Summary of the Invention
[0005] The purpose of this invention is to provide a method, apparatus, electronic device, and storage medium for acquiring process data, thereby reducing the system call overhead and implementation complexity of acquiring process metadata. The specific technical solution is as follows:
[0006] This invention first provides a method for acquiring process data, applied to an electronic device. The operating system of the electronic device has a preset file system mounted on it, which is used to store the file described by the process ID (PIDFD). The method includes:
[0007] When an instruction to retrieve the metadata of a target process is received, the inode of the file described by the PIDFD of the target process is determined as the target inode; wherein, the target inode records the address of the process descriptor information of the target process; and the process descriptor information of the target process records the address of the metadata of the target process.
[0008] The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode;
[0009] The metadata of the target process is obtained based on the address of the metadata recorded in the process descriptor information of the target process.
[0010] In one embodiment of the present invention, before receiving the instruction to obtain the metadata of the target process, the method further includes:
[0011] When the creation of the target process is detected, a target file is generated in the preset file system, a PIDFD is assigned to the target process, and an inode is generated for the target file;
[0012] Generate process descriptor information that includes the association between the target file and the target process, as well as the address of the metadata of the target process.
[0013] In one embodiment of the present invention, the process descriptor information of the target process records a reference count of the PIDFD of the target process in user mode; the method further includes:
[0014] When a user-space PIDFD retrieval request for the target process is detected, the reference count in the process descriptor information corresponding to the target process is incremented by 1;
[0015] When a user-space request to release the PIDFD of the target process is detected, the reference count in the process descriptor information corresponding to the target process is decremented by 1.
[0016] When it is detected that the reference count recorded in the process descriptor information corresponding to the target process is zero, the process of terminating the target process is executed.
[0017] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process; the method further includes:
[0018] When a control command is received for the target process, the target inode is determined based on the PIDFD of the target process;
[0019] The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode;
[0020] The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process.
[0021] The target process is controlled based on the determined process control information.
[0022] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process; the method further includes:
[0023] Receive a first search instruction for process control information of the target process; wherein the first search instruction includes the inode number of the file described by the PIDFD of the target process;
[0024] The target inode is determined based on the received inode number;
[0025] The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode;
[0026] The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process.
[0027] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process, and a persistent identifier that uniquely identifies the target process; the method further includes:
[0028] Receive a second retrieval instruction for process control information of the target process; wherein the second retrieval instruction includes a persistent identifier of the target process;
[0029] Determine the process descriptor information containing the persistent identifier to obtain the process descriptor information of the target process;
[0030] The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process.
[0031] In one embodiment of the present invention, the preset file system operation set includes functions for security detection; the method further includes:
[0032] When a specified operation against PIDFD is detected, the function for security detection is invoked to perform security checks on the operation to be performed.
[0033] This invention also provides a process data acquisition device applied to an electronic device, wherein the operating system of the electronic device has a preset file system mounted thereon, the preset file system being used to store the file described by the PIDFD; the device includes:
[0034] The first node determination module is used to determine the inode of the file described by the PIDFD of the target process as the target inode when it receives an instruction to obtain the metadata of the target process; wherein the target inode records the address of the process descriptor information of the target process; and the process descriptor information of the target process records the address of the metadata of the target process.
[0035] The first information determination module is used to determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode.
[0036] The metadata acquisition module is used to acquire the metadata of the target process based on the address of the metadata recorded in the process descriptor information of the target process.
[0037] This invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0038] Memory, used to store computer programs;
[0039] When a processor executes a program stored in memory, it implements any of the process data acquisition methods described above.
[0040] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the process data acquisition methods described above.
[0041] This invention also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the process data acquisition methods described above.
[0042] Beneficial effects of the embodiments of the present invention:
[0043] The process management method provided in this invention is applied to an electronic device. The operating system of the electronic device has a preset file system mounted to store files described by process descriptors (PIDFDs). When an instruction to retrieve the metadata of a target process is received, the inode of the file described by the PIDFD of the target process is determined as the target inode. Based on the address of the process descriptor information recorded in the target inode, the process descriptor information of the target process is determined. Then, based on the address of the metadata recorded in the process descriptor information of the target process, the metadata of the target process is retrieved. Therefore, in this solution, the metadata of a process can be obtained based on the inode without calling interfaces of other systems, thereby reducing system call overhead and implementation complexity.
[0044] Of course, implementing any product or method of the present invention does not necessarily require achieving all of the above advantages at the same time. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0046] Figure 1 This is a schematic diagram of the first process data acquisition method provided in an embodiment of the present invention;
[0047] Figure 2 This is a schematic diagram of a second process data acquisition method provided in an embodiment of the present invention;
[0048] Figure 3 This is a schematic diagram of the third process data acquisition method provided in the embodiments of the present invention;
[0049] Figure 4 This is a schematic diagram of the fourth process data acquisition method provided in the embodiments of the present invention;
[0050] Figure 5 This is a fifth flowchart illustrating the process data acquisition method provided in this embodiment of the invention.
[0051] Figure 6 This is a sixth flowchart illustrating the process data acquisition method provided in this embodiment of the invention.
[0052] Figure 7 This is an architecture diagram of the process data acquisition method provided in an embodiment of the present invention;
[0053] Figure 8This is a schematic diagram of the process data acquisition device provided in an embodiment of the present invention;
[0054] Figure 9 This is a schematic diagram of the structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation
[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on the present invention are within the scope of protection of the present invention.
[0056] The PIDFD mechanism in the Linux kernel has become a significant improvement in process management in recent years. The kernel implements PIDFD through anonymous inodes. Its core design stores the pointer to the `struct pid` (process descriptor structure) in the `private_data` field of the `struct file` (file structure), allowing user space to indirectly manipulate process objects through PIDFD. While this approach meets basic functional requirements, several architectural limitations have gradually emerged in practical applications. Because anonymous inodes are designed for general-purpose scenarios, they lack dedicated optimization space when handling process-specific semantics, resulting in the long-term inability to implement certain critical functions. For example, system calls like `statx` can only return basic file information when processing PIDFDs generated by anonymous inodes, failing to provide metadata related to process lifecycles. This lack of information forces developers to revert to traditional process inspection methods, effectively weakening the value of the PIDFD mechanism. These shortcomings are particularly acute in containerized environments. Container orchestration systems require precise control over the lifecycles of thousands of processes, while the existing PIDFD mechanism neither provides sufficient metadata support nor offers deterministic behavioral guarantees. When it's necessary to collect process statistics in bulk, it's unavoidable to use a mix of PIDFD and the traditional procfs interface, which requires frequent mode switching and context saving and recovery overhead. These drawbacks are particularly acute in containerized environments, where modern container orchestration systems need to precisely control the lifecycles of tens of thousands of processes, significantly increasing system call overhead and implementation complexity.
[0057] To address the aforementioned problems, embodiments of the present invention provide a process data acquisition method, apparatus, electronic device, and storage medium. This process data acquisition method is applied to an electronic device whose operating system has a preset file system mounted on it. This preset file system is used to store the file described by the process ID (PIDFD). The operating system can be a Linux system or another UNIX-like system, such as the Panning system. Specifically, the preset file system can be mounted at the VFS (Virtual File Systems) layer, and user-mode system calls can be routed to this preset file system through the VFS layer.
[0058] like Figure 1 As shown, the method may include the following steps:
[0059] S101, When the creation of the target process is detected, a target file is generated in the preset file system, a PIDFD is assigned to the target process, and an inode is generated for the target file;
[0060] For example, process creation can be achieved by calling the `fork` (forging) function or the `clone` (cloning) function. The target process can be any process in the operating system. When the target process is created, a target file can be generated synchronously in the preset file system, and a file descriptor can be allocated for the target file, thus using that file descriptor as the PIDFD of the target process. At the same time, the kernel will also generate an inode for the newly created file.
[0061] S102, Generate process descriptor information containing the relationship between the target file and the target process, and the address of the target process's metadata.
[0062] To establish the association between the target file and the target process, process descriptor information can be generated in the kernel. This process descriptor information can be in the form of a structure. Specifically, this process descriptor information can record both the inode number of the target file and a pointer to the process control information of the target process, thus establishing the association between the target file and the target process. The process control information can specifically be the target process's task_struck (process control block).
[0063] In this embodiment of the invention, the created processes and files in the preset file system have a one-to-one correspondence; that is, one process is associated with only one file in the preset file system, and one file in the preset file system is associated with only one process. The created processes and process descriptor information also have a one-to-one correspondence.
[0064] In related technologies, all PIDFDs generated based on the anonymous file mechanism share a single inode, and each struct pid maps to the same inode, making it impossible to distinguish different processes based on inode numbers. Although theoretically, independent inodes can be created using the anon_inode_create_getfile function (the kernel function for creating anonymous files), this results in different file descriptors of the same process being associated with different inodes. This makes it difficult for user-space tools to establish reliable criteria for determining file descriptor equivalence. For example, when verifying whether two PIDFDs point to the same process entity, a reliable basis for judgment cannot be found, thus affecting the correctness of the process monitoring system. When the parent process passes the PIDFD to the child process, because inode numbers lack stable and comparable semantics, it is impossible to reliably determine whether the PIDFDs held by the parent and child processes point to the same target process based on the inode number. This makes it difficult to accurately reconstruct and analyze the monitoring or control relationship between parent and child processes, and also makes it difficult for debugging tools to build a reliable process relationship graph. In addition, each creation of a PIDFD requires allocating independent storage space for the private_data field of the file structure, which also increases the risk of memory fragmentation.
[0065] In this embodiment of the invention, there is a one-to-one correspondence between processes and files in a preset file system. Thus, given an inode number, the user space can determine whether the inode number is associated with a process by checking if the file corresponding to that inode number is located in the preset file system. Furthermore, different processes can be distinguished based on the inode numbers of files in the preset file system. Only one process descriptor (PIDFD) is needed to uniformly record the association between files and processes. Therefore, for the same process, it is not necessary to allocate independent storage space for the `private_data` field of the `file` structure every time a PIDFD is created, thus avoiding the risk of memory fragmentation.
[0066] To facilitate the subsequent retrieval of the target process's metadata, the addresses of this metadata also need to be recorded in the process descriptor information. The target process's metadata can reside in structures such as `task_struct`, `signal_struct` (signal structure), and `mm_struct` (memory management structure). The addresses of the required metadata can be recorded in the process descriptor information as needed. For example, process metadata may include: process startup timestamp, resource usage statistics (CPU utilization, real-time virtual memory usage), scheduling priority, etc.
[0067] like Figure 2 As shown, after the process is created, embodiments of the present invention may further include the following steps:
[0068] S201, when receiving an instruction to obtain the metadata of the target process, determine the inode of the file described by the PIDFD of the target process as the target inode; wherein, the target inode records the address of the process descriptor information of the target process; the process descriptor information of the target process records the address of the metadata of the target process;
[0069] Since PIDFD is essentially a file descriptor, and a file has a corresponding inode in the kernel, the inode of a file can be determined by the PIDFD of the target process. In practice, the struct inode (index node structure) corresponding to the file can be determined based on the PIDFD.
[0070] The kernel can maintain a red-black tree in the super_block to efficiently manage inodes, ensuring O(log n) query performance even in scenarios with high frequency of creation and destruction.
[0071] Specifically, the `getattr` function (used to retrieve file attribute information) for steps S201-S203 can be set in the operation set of the preset file system to synthesize a `stat` (statistical) data structure containing process-specific attributes. When user space needs to obtain the metadata of a target process, the PIDFD of the target process can be passed to the `statx` function. When the electronic device detects that the `statx` function has been called, it can be regarded as receiving an instruction to obtain the metadata of the target process, and thus execute subsequent steps based on the `getattr` function in the operation set. The address of the process descriptor information can be recorded in the `i_private` field of the inode. In this way, in addition to standard file attributes such as file size and modification time, the caller can also obtain information such as the process's real-time virtual memory usage and scheduling priority.
[0072] S202, Determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode;
[0073] Since the target inode contains the address of the process descriptor information of the target process, the process descriptor information of the target process can be further located after the target inode is determined.
[0074] S203, Obtain the metadata of the target process based on the address of the metadata recorded in the process descriptor information of the target process.
[0075] Since the process descriptor information of the target process records the address of the target process's metadata, after determining the process descriptor information of the target process, the address of the target process's metadata can be located, thereby obtaining the target process's metadata.
[0076] As can be seen, in this embodiment, the process descriptor information directly interfaces with existing kernel structures such as `task_struct` and `signal_struct`. A single system call to the `statx` function can obtain the target process's metadata. While managing processes via PIDFD, there's no need to rely on `procfs` or other system interfaces to obtain process metadata, avoiding the performance overhead of redundant calculations. Calling the `statx` function not only returns traditional file attributes but also provides rich process-specific information, allowing user-space programs to obtain a complete view of the process state without using multiple interfaces. Furthermore, in this embodiment, the addresses of the metadata for different processes are recorded in their respective process descriptor information; therefore, this solution can also obtain the metadata of different processes separately for comparison operations.
[0077] In this embodiment, the operating system of the electronic device has a preset file system mounted for storing the file described by the PIDFD. When an instruction to obtain the metadata of the target process is received, the inode of the file described by the PIDFD of the target process is determined as the target inode. Based on the address of the process descriptor information recorded in the target inode, the process descriptor information of the target process is determined. Then, based on the address of the metadata recorded in the process descriptor information of the target process, the metadata of the target process is obtained. Therefore, in this solution, the metadata of the process can be obtained based on the inode without calling the interfaces of other systems, thereby reducing system call overhead and implementation complexity.
[0078] In one embodiment of the present invention, the process descriptor information of the target process also records the address of the process control information of the target process; such as Figure 3 As shown, the process data acquisition method also includes:
[0079] S301, when a control command for the target process is received, the target inode is determined based on the PIDFD of the target process;
[0080] For example, control instructions for a target process could be instructions to send signals to the target process, or instructions to kill, freeze, or reschedule the target process.
[0081] S302, determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode;
[0082] S303, Determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process;
[0083] S304, control the target process based on the determined process control information.
[0084] The aforementioned process control information can specifically be the process's `task_struct` structure. Similar to the previous embodiments, the framework provided by this invention can locate the corresponding process descriptor information based on the process's PIDFD. Since the process descriptor information records the address of the process control information, the process control information can be located based on the process's PIDFD, thereby enabling control of the target process.
[0085] In this embodiment, the process descriptor information also records the address of the process control information of the process. Therefore, the process control information of the process can still be located based on PIDFD, so that process control based on PIDFD can be realized based on the framework provided by the embodiment of the present invention.
[0086] In one embodiment of the present invention, if the process descriptor information of the target process also records the address of the process control information of the target process, such as... Figure 4 As shown, the process data acquisition method may also include:
[0087] S401, Receive a first search instruction for process control information of the target process; wherein, the first search instruction includes the inode number of the file described by the PIDFD of the target process;
[0088] S402, determine the target inode based on the received inode number;
[0089] S403, determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode;
[0090] S404. Determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process.
[0091] Since the processes in this embodiment correspond one-to-one with the files in the preset file system, the user space can also locate the corresponding process based on the inode number of the file in the preset file system, thereby obtaining the corresponding process control information.
[0092] In one embodiment of the present invention, the process descriptor information of the target process also records the address of the process control information of the target process, and a persistent identifier that uniquely identifies the target process; such as Figure 5 As shown, the process data acquisition method may also include:
[0093] S501, receive a second retrieval instruction for process control information of the target process; wherein, the second retrieval instruction includes the persistent identifier of the target process;
[0094] S502, determine the process descriptor information containing persistent identifiers, and obtain the process descriptor information of the target process;
[0095] S503, determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process.
[0096] In this embodiment, when the target process is created, a persistent identifier can be assigned to the target process, and this persistent identifier is recorded in the target process's process descriptor information. In this way, the user space can locate the target process's process control information based on the persistent identifier, and thus obtain the target process's process control information. Furthermore, this dual-indexing mechanism allows the user space to distinguish different PIDFDs based on inodes, and also to more reliably determine whether multiple PIDFDs point to the same process based on the persistent identifier.
[0097] In one embodiment of the present invention, the process descriptor information of the target process records the reference count of the PIDFD of the user-mode reference to the target process; such as Figure 6 As shown, the process data acquisition method may also include:
[0098] S601, when a user-mode request to obtain the PIDFD of the target process is detected, the reference count in the process descriptor information corresponding to the target process is incremented by 1;
[0099] In user space, after obtaining the PID (Process ID) of the target process, the `get_pid` function can be called. Therefore, when the `get_pid` function is called in user space for the target process, the reference count in the process descriptor information corresponding to the target process is incremented by 1.
[0100] S602, when a user-mode PIDFD release request for the target process is detected, the reference count in the process descriptor information corresponding to the target process is decremented by 1;
[0101] In user space, the `put_pid` function can be called after the PID (Process ID) of the target process is released. Therefore, when the `put_pid` function is called in user space for the target process, the reference count in the process descriptor information corresponding to the target process is decremented by 1.
[0102] S603, when it is detected that the reference count recorded in the process descriptor information corresponding to the target process is zero, the process of terminating the target process is executed.
[0103] For example, the process of terminating a target process could specifically refer to determining whether termination of the target process is permitted based on a preset policy. If the determination is yes, the target process is terminated; otherwise, it is not terminated. When the target process terminates, associated files, directories, and inodes in the preset file system can also be cleaned up accordingly.
[0104] In this embodiment, atomic operations atomic_inc (incrementing the atomic variable by 1) and atomic_dec_and_test (decrementing the atomic variable by 1 and checking if it is 0) and memory barriers can be used to ensure the accuracy of counting in a multi-core environment. At the same time, the RCU (Read-Copy-Update) mechanism is used to handle concurrent reading scenarios.
[0105] In related technologies, the `struct pid` structure does not have a separate count for file descriptor references, making it difficult to implement precise process termination strategies. Basic requirements such as `kill-on-last-close` (killing the process on the last close) cannot be achieved using the current PIDFD mechanism. This causes the kernel to be unable to distinguish between file descriptor closing and reference release by other subsystems. This problem is particularly prominent in long-running daemons, potentially leading to serious consequences such as resource leaks or premature termination.
[0106] This embodiment can distinguish between two types of file descriptor references in the preset file system operation set: user-mode file descriptor references and kernel internal references. This allows the kernel to specifically record the reference count of user-mode PIDFD in the process descriptor information. The kernel can accurately detect the closing event of the last user-mode file descriptor without being interfered with by the reference counts of other kernel subsystems, thus providing an implementation basis for kill-on-last-close.
[0107] Furthermore, in this embodiment, a process descriptor is associated with only one process. When performing reference counting on multiple processes, it is not necessary to frequently lock and unlock the same struct pid structure, thus avoiding race conditions and reducing synchronization overhead in a multi-threaded environment.
[0108] In one embodiment of the present invention, the preset file system operation set includes functions for security detection; the process data acquisition method may further include:
[0109] When a specified operation against PIDFD is detected, a function for security checks is invoked to perform security checks on the operation to be performed.
[0110] The specified operations for a PIDFD can include: creating a PIDFD, obtaining a PIDFD, exercising control over a process through a PIDFD, obtaining process metadata or sensitive metadata through a PIDFD, etc.
[0111] Every specified operation on a PIDFD undergoes a credential check, especially for cross-namespace access requests. For example, permission verification of the initiator is performed during the PIDFD creation phase. Subsequent operations on the created PIDFD only require verification of the PIDFD itself. This optimization reduces the overhead of redundant security checks, enhancing the support for the audit subsystem. Furthermore, the default file system operation set can be configured with logging operations, ensuring that each specified operation generates a detailed audit log after execution, recording information such as the operation type, initiating process, and timestamp.
[0112] In this embodiment, by setting a function for security detection in the operation set of the preset file system, when a specified operation against PIDFD is detected, the function for security detection is called to perform security detection on the operation to be executed, which can improve the security of the PIDFD mechanism.
[0113] In a specific application scenario, the architecture of this invention embodiment can be as follows: Figure 7 As shown, the struct file corresponding to PIDFD records the inode number corresponding to PIDFD. Based on this inode number, the struct inode can be located. The struct inode records the address of the process descriptor information, which can further locate the process descriptor information corresponding to PIDFD. The process descriptor information can record the inode number corresponding to PIDFD, the persistent identifier of the process represented by PIDFD, the address of process control information, the address of metadata, and the reference count of user-space references to PIDFD. Based on the address of the process control information recorded in the process descriptor information, the process control information of the process corresponding to PIDFD, i.e., task_struct, can be located.
[0114] This solution employs a unified, process-centric storage approach, eliminating the need to record the `struct pid` pointer in the `private_data` field of the `file` structure. This allows the field to be freely used by various file options of `PIDFD`, reserving interface space for potential expansion while maintaining binary compatibility with older kernel versions. In practice, a simple `mount` operation activates the default file system, which is completely transparent to existing user-space code. The default file system has a flat structure, eliminating the need for complex directory lookups. This lightweight design enables the system to achieve precise control without adding excessive overhead. Furthermore, the operating system retains the ability to revert to the traditional anonymous inode mechanism; this gradual improvement strategy significantly reduces deployment risks.
[0115] Benchmark tests show that the statx system call based on this invention improves the speed of obtaining complete process information by approximately 40% compared to the previous method of using multiple interfaces. This is crucial for system monitoring tools. When monitoring the resource usage of 1000 active processes, this solution reduced sampling latency by 57% and CPU utilization by 23%. The reliability of the kill-on-last-close function reached 100% (zero errors in 100,000 random tests). From a system architecture perspective, developers can add new process attributes by extending the structure of process descriptor information without breaking the existing ABI (Application Binary Interface). Performance profiling shows that the system call processing path based on this invention is shortened by 15%. Furthermore, the completeness of audit logs is improved, and all critical operations have comprehensive traceability capabilities.
[0116] Based on the same inventive concept, embodiments of the present invention also provide a process data acquisition device, applied to an electronic device, wherein the operating system of the electronic device has a preset file system mounted thereon, the preset file system being used to store the file described by the PIDFD; such as Figure 8 As shown, the device includes:
[0117] The first node determination module 801 is used to determine the inode of the file described by the PIDFD of the target process as the target inode when it receives an instruction to obtain the metadata of the target process; wherein the target inode records the address of the process descriptor information of the target process; and the process descriptor information of the target process records the address of the metadata of the target process.
[0118] The first information determination module 802 is used to determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode.
[0119] The metadata acquisition module 803 is used to acquire the metadata of the target process based on the address of the metadata recorded in the process descriptor information of the target process.
[0120] In one embodiment of the present invention, the apparatus further includes: a creation module, configured to, before receiving an instruction to obtain the metadata of the target process, when the creation of the target process is detected, generate a target file in the preset file system, assign a PIDFD to the target process, and generate an inode for the target file; and generate process descriptor information containing the association between the target file and the target process, and the address of the metadata of the target process.
[0121] In one embodiment of the present invention, the process descriptor information of the target process records a reference count of the PIDFD of the target process in user mode; the apparatus further includes:
[0122] The counter increment module is used to increment the reference count in the process descriptor information corresponding to the target process by 1 when a user-space PIDFD acquisition request for the target process is detected.
[0123] The decrementing module is used to decrement the reference count in the process descriptor information corresponding to the target process by 1 when a user-space release request for the PIDFD of the target process is detected.
[0124] The termination module is used to execute the process of terminating the target process when it is detected that the reference count recorded in the process descriptor information corresponding to the target process is zero.
[0125] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process; the apparatus further includes:
[0126] The second node determination module is used to determine the target inode based on the PIDFD of the target process when a control command for the target process is received.
[0127] The second information determination module is used to determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode.
[0128] The third information determination module is used to determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process.
[0129] The control module is used to control the target process based on the determined process control information.
[0130] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process; the apparatus further includes:
[0131] The first instruction receiving module is configured to receive a first retrieval instruction for process control information of the target process; wherein the first retrieval instruction includes the inode number of the file described by the PIDFD of the target process.
[0132] The third node determination module is used to determine the target inode based on the received inode number;
[0133] The fourth information determination module is used to determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode;
[0134] The fifth information determination module is used to determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process.
[0135] In one embodiment of the present invention, the process descriptor information of the target process further records the address of the process control information of the target process, and a persistent identifier that uniquely identifies the target process; the apparatus further includes:
[0136] The second instruction receiving module is used to receive a second retrieval instruction for process control information of the target process; wherein the second retrieval instruction includes a persistent identifier of the target process;
[0137] The sixth information determination module is used to determine the process descriptor information containing the persistent identifier, and obtain the process descriptor information of the target process;
[0138] The seventh information determination module is used to determine the process control information of the target process based on the address of the process control information recorded in the process descriptor information of the target process.
[0139] In one embodiment of the present invention, the operation set of the preset file system is provided with functions for security detection; the device further includes:
[0140] The security detection module is used to call the security detection function to perform security detection on the operation to be performed when a specified operation against PIDFD is detected.
[0141] This invention also provides an electronic device, such as... Figure 9As shown, it includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.
[0142] Memory 903 is used to store computer programs;
[0143] The processor 901, when executing a program stored in the memory 903, implements any of the process data acquisition methods described above.
[0144] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0145] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0146] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0147] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0148] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described process data acquisition methods.
[0149] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the process data acquisition methods described above.
[0150] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0151] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0152] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0153] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A method for acquiring process data, characterized in that, Applied to electronic devices, wherein the operating system of the electronic device has a preset file system mounted thereon, the preset file system being used to store the file described by the PIDFD; the method includes: When an instruction to retrieve the metadata of a target process is received, the inode of the file described by the PIDFD of the target process is determined as the target inode; wherein, the target inode records the address of the process descriptor information of the target process; and the process descriptor information of the target process records the address of the metadata of the target process. The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode; The metadata of the target process is obtained based on the address of the metadata recorded in the process descriptor information of the target process; wherein the structure in which the metadata of the target process is located includes: the process control block structure, the signal structure, and the memory management structure of the target process; Before receiving the instruction to retrieve the metadata of the target process, the method further includes: When the creation of the target process is detected, a target file is generated in the preset file system, a PIDFD is assigned to the target process, and an inode is generated for the target file; wherein, the created process corresponds one-to-one with the file in the preset file system; Generate process descriptor information that includes the association between the target file and the target process, as well as the address of the metadata of the target process.
2. The method according to claim 1, characterized in that, The process descriptor information of the target process records the reference count of the PIDFD of the target process in user mode; the method further includes: When a user-space PIDFD retrieval request for the target process is detected, the reference count in the process descriptor information corresponding to the target process is incremented by 1; When a user-space request to release the PIDFD of the target process is detected, the reference count in the process descriptor information corresponding to the target process is decremented by 1. When it is detected that the reference count recorded in the process descriptor information corresponding to the target process is zero, the process of terminating the target process is executed.
3. The method according to claim 1, characterized in that, The process descriptor information of the target process also records the address of the process control information of the target process; the method further includes: When a control command is received for the target process, the target inode is determined based on the PIDFD of the target process; The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode; The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process. The target process is controlled based on the determined process control information.
4. The method according to claim 1, characterized in that, The process descriptor information of the target process also records the address of the process control information of the target process; the method further includes: Receive a first search instruction for process control information of the target process; wherein the first search instruction includes the inode number of the file described by the PIDFD of the target process; The target inode is determined based on the received inode number; The process descriptor information of the target process is determined based on the address of the process descriptor information recorded in the target inode; The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process.
5. The method according to claim 1, characterized in that, The process descriptor information of the target process also records the address of the process control information of the target process, and a persistent identifier that uniquely identifies the target process; the method further includes: Receive a second retrieval instruction for process control information of the target process; wherein the second retrieval instruction includes a persistent identifier of the target process; Determine the process descriptor information containing the persistent identifier to obtain the process descriptor information of the target process; The process control information of the target process is determined based on the address of the process control information recorded in the process descriptor information of the target process.
6. The method according to claim 1, characterized in that, The preset file system operation set includes functions for security detection; the method further includes: When a specified operation against PIDFD is detected, the function for security detection is invoked to perform security checks on the operation to be performed.
7. A process data acquisition device, characterized in that, An electronic device, wherein the operating system of the electronic device has a preset file system mounted thereon, the preset file system being used to store the file described by the PIDFD; the device includes: The first node determination module is used to determine the inode of the file described by the PIDFD of the target process as the target inode when it receives an instruction to obtain the metadata of the target process; wherein the target inode records the address of the process descriptor information of the target process; and the process descriptor information of the target process records the address of the metadata of the target process. The first information determination module is used to determine the process descriptor information of the target process based on the address of the process descriptor information recorded in the target inode. The metadata acquisition module is used to acquire the metadata of the target process based on the address of the metadata recorded in the process descriptor information of the target process; wherein, the structure in which the metadata of the target process is located includes: the process control block structure, the signal structure, and the memory management structure of the target process; The device further includes: a creation module, configured to, before receiving an instruction to obtain the metadata of the target process, when the creation of the target process is detected, generate a target file in the preset file system, assign a PIDFD to the target process, and generate an inode for the target file; wherein the created process corresponds one-to-one with the file in the preset file system; and generate process descriptor information containing the association between the target file and the target process, and the address of the metadata of the target process.
8. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-6.