A process recovery method, product, device and storage medium
By adding a magic number to the process control block and identifying memory data when the new kernel starts, fast process recovery is achieved, solving the problem of time-consuming disk data recovery during kernel upgrades, improving process recovery efficiency and reducing business interruption time.
Patent Information
- Application Number
- CN202510237669.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-28
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-02-28
AI Technical Summary
In the prior art, during a kernel upgrade, it takes a long time to read memory data from the disk and put it back into the memory when the process is restored, resulting in a long business interruption time and affecting business operations.
A magic number is pre-added to the process control block of the target software. The process control block is identified by detecting the magic number when the new kernel is started. The data in the process control block and the process context information are retained in the system memory. The process is recovered directly in the memory, reducing the data recovery process from disk to memory.
This improves the efficiency of process recovery, shortens business interruption time, and reduces the impact of kernel switching on business.
Smart Images

Figure CN120029827B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a process recovery method, product, device and storage medium. BACKGROUND
[0002] In the development process of large software, vulnerabilities are inevitable problems. As the core of the operating system, the kernel (such as Linux kernel) once exploited maliciously, may lead to system crash, data leakage or even remote control and other serious consequences. By kernel upgrade, these known vulnerabilities can be fixed, reducing the risk of attack, and regular kernel updates can introduce new security features and defense mechanisms, improving the defense capability of the system against new attacks and the security and stability of the business.
[0003] However, as the core of the operating system, switching the kernel requires restarting the system, completely shutting down the current kernel, and starting the system from the new kernel to complete the kernel switching. For example, the current Linux operating system usually updates the kernel through the Kexec tool (a system call tool) or restarts, and completes the saving and restoring of process data by restarting the software or using the CRIU (Checkpoint / Restore In Userspace, a tool for Linux to provide checkpoint / restore functions) tool to achieve kernel upgrade and process recovery. But the above kernel update method needs to go through a system call to complete the old kernel shutdown and new kernel startup; and in actual use, the memory of the key process is usually large, and the way of reading memory data and writing it to the disk, and then reading the saved memory data from the disk and putting it back into the memory, will cause a lot of time-consuming, resulting in longer interruption of business. In addition, during the operating system restart process, the software running on the system will be terminated, and the system will be unavailable for a short time, thereby affecting the ongoing business operation. SUMMARY
[0004] The present application provides a process recovery method, product, device and storage medium to at least solve the problem of time-consuming reading memory data from disk and putting it back into memory when recovering the process in related technologies.
[0005] The present application provides a process recovery method, comprising:
[0006] When a kernel switching task needs to be executed, a process control block containing a preset magic number in the current system memory is detected;
[0007] A target process corresponding to the target software requiring kernel switching is run, and context information in the running process of the target process is collected to obtain process context information;
[0008] loading the new kernel into a preset memory space and restarting the operating system from the new kernel located in the preset memory space;
[0009] When the new kernel is detected to be started, a process control block is identified based on a preset magic number in a target memory address, and data in the process control block and process context information in a running process of the target process are reserved in system memory;
[0010] When the operating system is detected to be started, the process context information and the data in the process control block are read to create a new process in the system memory, and the target process is restored in the new process based on the process context information and the data in the process control block.
[0011] The application further provides an electronic device, comprising a memory for storing a computer program and a processor for executing the computer program to implement the steps of any of the process restoration methods.
[0012] The application further provides a computer readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the steps of any of the process restoration methods are implemented.
[0013] The application further provides a computer program product, which comprises a computer program, and when the computer program is executed by a processor, the steps of any of the process restoration methods are implemented.
[0014] According to the application, since the magic number is added in advance in the process control block corresponding to the target software, the process control block corresponding to the target software can be quickly identified based on the magic number when the process is restored. In addition, when the new kernel is detected to be started, the process control block is identified based on the magic number in the target memory address, and the data in the process control block and the process context information in the running process of the target process are reserved in the system memory. In this way, the target process can be directly restored according to the information recorded in the system memory (including the data in the process control block corresponding to the target process and the process context information). Compared with the process restoration method of saving the process restoration data in the disk and reading the process restoration data from the disk, by adding the magic number in the process control block and identifying and reserving the key memory data for process data restoration after the new kernel is started, the data recovery process from the disk to the memory can be reduced, and the time consumption of the process restoration is reduced, thereby improving the efficiency of the process restoration and reducing the impact on the business operation. Therefore, the time-consuming problem of reading the memory data in the disk and returning it to the memory during process restoration can be solved, the process restoration speed can be greatly improved, the business interruption time can be shortened, and the impact of kernel switching on the business can be reduced. BRIEF DESCRIPTION OF DRAWINGS
[0015] In order to more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without any creative effort based on these drawings.
[0016] Figure 1 A process recovery method flow chart provided by the embodiments of the present application;
[0017] Figure 2 A system memory schematic diagram before process recovery provided by the embodiments of the present application;
[0018] Figure 3 A system memory schematic diagram after process recovery provided by the embodiments of the present application;
[0019] Figure 4 A specific process recovery method flow chart provided by the embodiments of the present application. DETAILED DESCRIPTION
[0020] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without any creative effort are within the protection scope of the present application.
[0021] It should be noted that, in the description of the present application, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that the processes, methods, articles or devices comprising a series of elements not only include those elements, but also include other elements not explicitly listed or inherent to such processes, methods, articles or devices. The terms "first", "second" and the like in the present application are used to distinguish similar objects, not to describe a specific order or sequence.
[0022] In order to make the skilled in the art better understand the present application, the present application will be further described in detail below with reference to the drawings and specific embodiments.
[0023] The embodiments of the present application disclose a process recovery method, referring to Figure 1 The method comprises the following steps:
[0024] Step S11: When a kernel switching task needs to be executed, a process control block containing a preset magic number in the current system memory is detected.
[0025] In this embodiment, when the operating system (such as Linux kernel) needs to perform a kernel switching task (such as kernel upgrade / downgrade), first, the memory usage of the process that needs to be quickly recovered after kernel switching is detected, and specifically, the distribution of the key memory data flag (i.e. preset magic number) in the system memory is detected, thereby obtaining the process control block (PCB, process control block) containing the preset magic number.
[0026] The process control block is a data structure used by the operating system to manage the process, and contains all important information related to the process. The saved information can specifically include: 1, process state information, used to indicate the current state of the process (such as ready, running, waiting, etc.); 2, program counter information, used to point to the next instruction address to be executed; 3, register information, including general registers, stack pointers, etc., recording the state of the process when running; 4, memory management information, such as page table or segment table, recording the memory address information used by the process; 5, scheduling information, such as priority, scheduling queue pointer, etc., used for process scheduling; 6, I / O (Input / Output, input / output) state information, recording the I / O devices used by the process and related information.
[0027] It should be noted that the present application needs to prepare the corresponding system environment before the process is recovered, so as to realize the process recovery process. Specifically, before detecting the process control block containing the preset magic number in the current system memory, it specifically further includes: configuring system startup boot parameters; the system startup boot parameters include first boot parameters, second boot parameters and third boot parameters; wherein the first boot parameters are used to specify the target memory address to save the key memory data flag, the second boot parameters are used to indicate whether to select to retain the key memory data, and the third boot parameters are used to specify the preset magic number as the key memory data flag; when detecting the operating system startup, adding the preset magic number in the target memory address located in the system memory; in the running process of the operating system, judging whether the target software needs to be recovered after the kernel switching; if the target software needs to be recovered after the kernel switching, calling the preset system tool to start the target process corresponding to the target software, and adding the preset magic number in the target memory address in the process control block of the target process. In the embodiment, three system startup boot parameters are configured in advance, which are first boot parameters (boot parameter 1), second boot parameters (boot parameter 2) and third boot parameters (boot parameter 3); wherein the first boot parameters (boot parameter 1) are used to specify a target memory address to save the key memory data flag, the second boot parameters (boot parameter 2) are used to indicate whether to select to retain the key memory data, and the third boot parameters (boot parameter 3) are used to specify the preset magic number as the key memory data flag. Wherein, the preset magic number refers to the numerical constant of the key memory data flag; the key memory data refers to all memory data required for recovering a target process. Then, when detecting the operating system startup, the preset magic number is added in the target memory address located in the system memory, and in the running process of the operating system, it is judged whether the target software needs to be recovered after the kernel switching, if it needs to be recovered after the kernel switching, the preset system tool is called to start the target process corresponding to the target software, and the preset magic number (i.e. the key memory data flag) in the target memory address is added in the process control block of the target process, as shown in Figure 2 A magic number is set in the system memory, and the magic number is added in the process control block of the target process. By adding the magic number, the related process control block of the target process can be quickly and accurately identified, so as to facilitate the subsequent process control block searching and recovery in the process recovery process, thereby improving the efficiency of the process recovery.
[0028] In a specific embodiment, the preset magic number is added to the target memory address in the system memory, which can specifically include: generating a random number through a true random function, and adding the generated random number as the preset magic number to the target memory address in the system memory. In this embodiment, a random number can be first generated through a true random function, and then the random number is added as the preset magic number to the target memory address in the system memory. The magic number generated by the true random function can avoid data collision.
[0029] In another specific embodiment, the preset magic number can also be specified through a command line parameter. In addition, after the operating system is started, a / proc / magicnum interface can be provided to view the specific value of the preset magic number. The / proc is a virtual file system, which provides an interface through which kernel and process information can be accessed, and provides a view of kernel data for user space programs, so that users can obtain system status and process information by reading files.
[0030] Specifically, adding the preset magic number in the target memory address in the process control block of the target process can include: adding the preset magic number in the target memory address in the process control block of the target process and the process control block of the child process generated by the target process. In this embodiment, if the target process has been started, the system tool can add the key memory data flag (i.e. the preset magic number) to the process control block of the current target process, and the process control block of the child process generated by the target process will also be set with the same key memory data flag (i.e. the preset magic number).
[0031] Step S12: running the target process corresponding to the target software requiring kernel switching, and collecting the context information of the target process during running to obtain process context information.
[0032] In this embodiment, after detecting the process control block containing the preset magic number in the current system memory, the target process corresponding to the target software requiring kernel switching is further run, and the context information of the target process during running is collected to obtain process context information. The process context information includes but is not limited to file description information ( / proc / pid / fd / and / proc / pid / fdinfo / ), register state information, inter-process communication parameter information, memory table ( / proc / pid / maps / and / proc / pid / map_files / ), process environment ( / proc / pid / environ and / proc / pid / cmdline) information, and process tree information.
[0033] Specifically, a target process corresponding to the target software requiring kernel switching is run, and context information in a running process of the target process is collected to obtain process context information, which can include: a target process corresponding to the target software requiring kernel switching is dynamically injected through a system call mechanism, and the target process is run; context information in a running process of the target process is collected from a preset virtual file system to obtain process context information. For example, a target process corresponding to the target software requiring kernel switching is dynamically injected through a ptrace (a Linux system call) mechanism and run, and all context information of the target process is collected from a / proc file system (a virtual file system in Linux).
[0034] Further, after collecting context information in a running process of the target process to obtain process context information, the process context information and data in the process control block can be saved in the disk in the form of a mirror file; the process context information includes memory tables and process tree information; and addresses and lengths of key memory regions occupied by the target process are recorded in the disk. In this embodiment, after all data related to the target process (including process context information and data in the process control block) is collected, the data is saved in the disk in the form of a mirror file, and addresses and lengths of key memory regions occupied by the target process are recorded in the disk. It can be understood that if the memory usage of the target process is large, saving memory data in the disk in the form of a mirror file will consume a lot of time, at which time the memory mirror data can be abandoned, and only the memory tables in the context information are retained.
[0035] Step S13: loading a new kernel into a preset memory space, and restarting an operating system from the new kernel located in the preset memory space.
[0036] In this embodiment, after collecting context information in a running process of the target process, kernel switching can be performed through a Kexec tool. Specifically, a new kernel can be loaded into a preset memory space in a system memory, and then the operating system is restarted from the loaded new kernel through a system restart call. Compared with directly restarting the system to perform kernel switching, the time for hardware booting and kernel loading during booting can be reduced.
[0037] Step S14: when it is detected that the new kernel is started, identifying a process control block based on a preset magic number in a target memory address, and retaining data in the process control block and process context information in the system memory.
[0038] In this embodiment, when it is detected that the new kernel is started, a corresponding process control block can be identified based on a preset magic number saved in a target memory address, and data in the identified process control block and process context information are retained in the system memory.
[0039] Specifically, when detecting the new kernel starting, the process control block is identified based on the preset magic number in the target memory address, which can include: when detecting the new kernel starting, detecting a second boot parameter in system startup boot parameters, if the second boot parameter indicates that the critical memory data is selected to be reserved, detecting a target memory address for saving the critical memory data flag, and reading the preset magic number from the target memory address; when the system memory is initialized, the data in the system memory is traversed and detected using the preset magic number, so as to identify the process control block containing the preset magic number. In the embodiment, when detecting the new kernel starting, the system startup boot parameters are first detected, if the second boot parameter in the system startup boot parameters indicates that the critical memory data is selected to be reserved, the target memory address for saving the critical memory data flag is further detected, then the preset magic number is read from the target memory address, and when the system memory is initialized, the data in the system memory is traversed and detected using the preset magic number, so as to identify all process control blocks containing the preset magic number. It should be noted that in the case that the system startup boot parameter configuration is successful, the process data can be successfully triggered to be quickly recovered whether the Kexec tool or the restart mode is used.
[0040] In addition, it should be noted that in order to ensure that the identified process control block is the effective control block related to the target process, the identified process control block can be detected. Specifically, when the system memory is initialized, the data in the system memory is detected by searching for the preset magic number, so as to find the memory area containing the magic number, and then the memory area is parsed in the process control block structure of the operating system code. Only when the value of the magic number is correct, and the data in the memory area is consistent with the defined arrangement of the process control block, and the pid (process identifier) field, the name field and the like are valid values, it can be confirmed that the memory area at this position is a valid process control block.
[0041] Specifically, the data in the process control block and the process context information reserved in the system memory can include: identifying a memory data area used by the target process according to the process control block, reserving data in the memory data area, and initializing other memory areas except the memory data area; the memory data area includes the data in the process control block and the process context information. In this embodiment, the memory data area used by the target process can be identified according to the process control block first, which includes the data in the process control block and the process context information such as process context, file descriptor and corresponding page cache information, and then the data in the memory data area required by the recovery process is reserved, and other memory areas except the memory data area are normally initialized. It can be understood that, since the device is not powered off in the reboot process, the data in the memory will not disappear.
[0042] Step S15: When it is detected that the operating system is started, the data in the process control block and the process context information are read to create a new process in the system memory, and the target process is recovered in the new process based on the data in the process control block and the process context information.
[0043] In this embodiment, when it is detected that the operating system is started, the reserved process context information and the data in the process control block can be directly read from the system memory to create a new process in the system memory, and then the target process is recovered in the new process based on the data in the process control block and the process context information.
[0044] In this embodiment, reading the process context information and the data in the process control block can specifically include: detecting whether the key memory area matches the memory data area based on the address and length of the key memory area recorded in the disk; if the key memory area matches the memory data area, the process context information and the data in the process control block are read from the system memory. In this embodiment, after the operating system is started, the process context information saved in the disk before the kernel switch and the address and length corresponding to the key memory area can be read first, and then it is detected whether the current key memory area matches the saved memory data area based on the above information. If they match, the process context information and the data in the process control block are read from the system memory for process data recovery. Through matching detection, it can be ensured that the process recovery is based on correct memory data, thereby avoiding recovery failure.
[0045] In the embodiment, if the critical memory region does not match the memory data region, the process context information and the data in the process control block saved in the disk are recovered to the system memory, and a step of reading the process context information and the data in the process control block is triggered. In the embodiment, if the critical memory region does not match the memory data region, the process context information and the data in the process control block saved in the disk can be recovered to the corresponding region in the system memory, and a flow of reading the data in the memory and performing process recovery is triggered. That is, if there is a loss in the memory data region saved in the system memory, the corresponding data saved in the disk is recovered to the system memory. In order to improve the matching speed, whether the matching is successful can be determined by detecting the size of the memory region, without detecting whether the data in the system memory matches.
[0046] Correspondingly, the target process is recovered in the new process based on the process context information and the data in the process control block, including: creating a process tree based on the process tree information in the process context information; and recovering the target process and a child process generated by the target process on the process tree based on the process context information and the data in the process control block. In the embodiment, for a process recovery scenario including multiple child processes, a new process can be started after the system memory is detected, and the original process tree structure can be reconstructed by multiple fork calls. Specifically, for each saved process (including the target process and the corresponding child process), a new process is created to become a child process of the recovered process tree, and then the process state information saved in the disk in the mirror file is recovered in the new process, including recovering the memory address of the process, setting the state of the register and the program counter, reopening the file descriptor and the network connection, and the like, and then the parent process of the new process is set according to the original process tree structure, so as to ensure that the recovered process tree is the same as the original process tree. After the process tree is created, the critical memory data saved in the system memory can be mapped to the newly created process, and the required socket and mount point are created or mapped, and then the context data of the process running is recovered, so as to realize the recovery of the target process and the corresponding child process.
[0047] Further, after the target process and the child process generated by the target process are recovered on the process tree, the code of the target process is executed, and the command line parameters and the environment variables of the target process are passed, so as to switch the context of the new process to the context of the target process. In the embodiment, after the target process and the child process generated by the target process are recovered on the process tree, that is, after the state of the new process is recovered, the execve() system call can be used to execute the code of the target process, and then the command line parameters and the environment variables of the target process are passed, so as to switch the context of the new process to the context of the target process. Specifically, as shown in FIG. 6, the process tree is created based on the process tree information in the process context information, and then the process context information and the data in the process control block are recovered to the system memory, and the process tree is recovered based on the process context information and the data in the process control block. Figure 3As shown, a new process for restoring the target process is created in the system memory, and the data in the target process is restored in the new process, and the data in the process control block corresponding to the target process is released after the restoration, and then the code of the target process is executed, and the command line parameters and environment variables of the target process are passed, so as to switch the context of the new process to the context of the target process.
[0048] In addition, if the memory information reservation in the system memory fails or the process restoration fails due to a memory error, the process that needs to be reserved can be restored through the memory image file saved in the disk. If the memory image file in the disk does not exist or the image file restoration fails, the original data of the target process will be abandoned, and a process will be restarted, thereby ensuring the existence of the process and the service.
[0049] It can be seen that the embodiment of the application adds the magic number in the process control block corresponding to the target software in advance, so that the process control block corresponding to the target software can be quickly identified based on the magic number during process restoration. In addition, when the new kernel is detected to be started, the process control block is identified based on the magic number in the target memory address, and the data in the process control block and the process context information in the running process of the target process are reserved in the system memory. In this way, the target process can be directly restored according to the information recorded in the system memory (including the data in the process control block corresponding to the target process and the process context information). Compared with the process restoration method of saving process restoration data in the disk and reading process restoration data from the disk, the embodiment of the application adds the magic number in the process control block, and identifies and reserves the key memory data after the new kernel is started for process data restoration, which can reduce the data restoration process from the disk to the memory and reduce the time consumption of process restoration, thereby improving the efficiency of process restoration and reducing the impact on service operation. Therefore, the time-consuming problem of reading the memory data in the disk and returning it to the memory during process restoration can be solved, the process restoration speed can be greatly improved, the service interruption time can be shortened, and the impact of kernel switching on the service can be reduced.
[0050] The embodiment of the application discloses a specific process restoration method, which is shown in Figure 4 The method comprises the following steps:
[0051] Step S21: When a kernel switching task needs to be performed, a process control block containing a preset magic number in the current system memory is detected.
[0052] Step S22: A target process corresponding to a target software that needs to be kernel switched is run, and context information in the running process of the target process is collected to obtain process context information.
[0053] Step S23: shielding the central processor logic cores except the default central processor logic core.
[0054] In this embodiment, after the context information of the target process in the running process is collected, considering that a large number of central processor logic cores will cause a long time consumption of the offline operation, the central processor logic cores except the default central processor logic core (such as CPU0) are shielded.
[0055] Step S24: loading the new kernel into the preset memory space, and restarting the operating system from the new kernel in the preset memory space.
[0056] Step S25: when it is detected that the new kernel is started, identifying the process control block based on the preset magic number in the target memory address, reserving the data and the process context information in the process control block in the system memory, and then sequentially reactivating each other central processor logic core.
[0057] In this embodiment, when it is detected that the new kernel is started, the process control block containing the preset magic number can be identified based on the preset magic number in the target memory address, and then the data and the process context information in the process control block are reserved in the system memory, and then each other central processor logic core (such as CPU1, CPU2, etc.) is sequentially reactivated.
[0058] Step S26: when it is detected that the operating system is started, reading the process context information and the data in the process control block, to create a new process in the system memory, and restoring the target process in the new process based on the process context information and the data in the process control block.
[0059] The more specific processing procedures of the above steps S21, S22, S24, and S26 can refer to the corresponding contents disclosed in the foregoing embodiments, and will not be described here.
[0060] It can be seen that, before switching the kernel, the embodiments of the present application shield the central processor logic cores except the default central processor logic core, and then sequentially reactivate the shielded central processor logic cores after the new kernel is started. By shielding the interrupts and communications of the central processor logic cores except the default central processor logic core, the serial central processor logic core offline operation is modified to the parallel central processor logic core offline operation, thereby reducing the time consumption of the central processor logic core offline, and enabling the process data to be quickly restored after the new kernel is started, thereby reducing the process recovery time and ensuring the fast operation of the business.
[0061] The embodiment of the present application further provides a process recovery device, and the features of the embodiment of the process recovery device can be referred to the related description of the embodiment of the process recovery method, which will not be repeated here.
[0062] The embodiment of the present application further provides an electronic device, which comprises a memory and a processor, the memory stores a computer program, and the processor is configured to execute the computer program to perform the steps in any of the process recovery method embodiments.
[0063] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is configured to perform the steps in any of the process recovery method embodiments when executed.
[0064] In an example embodiment, the computer readable storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.
[0065] The embodiment of the present application further provides a computer program product, which comprises a computer program, and the computer program is executed by a processor to perform the steps in any of the process recovery method embodiments.
[0066] The embodiment of the present application further provides another computer program product, which comprises a non-volatile computer readable storage medium, and the non-volatile computer readable storage medium stores a computer program, and the computer program is executed by a processor to perform the steps in any of the process recovery method embodiments.
[0067] The skilled person can further realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be realized by electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of the examples have been described in general terms in the above description. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.
[0068] The process recovery method, product, device and storage medium provided by the present application are described in detail above. The principles and implementation modes of the present application are described by applying specific examples, and the above description of the examples is only used to help understand the method of the present application and its core idea. It should be pointed out that, for ordinary skilled persons in the technical field, some improvements and modifications can be made to the present application without departing from the principles of the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.
Claims
1. A process recovery method, characterized in that: include: When a kernel switching task needs to be executed, the process control block containing the preset magic number in the current system memory is detected; Running a target process corresponding to the target software that requires kernel switching, and collecting context information during the running of the target process to obtain process context information; Loading a new kernel into a preset memory space, and restarting the operating system from the new kernel in the preset memory space; When detecting that the new kernel is started, identifying the process control block based on the preset magic number in the target memory address, and retaining the data in the process control block and the process context information in the system memory; When it is detected that the operating system is started, the process context information and the data in the process control block are read to create a new process in the system memory, and the target process is restored in the new process based on the process context information and the data in the process control block.
2. The process recovery method according to claim 1, characterized in that: Before detecting the process control block containing the preset magic number in the current system memory, the method further includes: Configuring system startup boot parameters; the system startup boot parameters include a first boot parameter, a second boot parameter, and a third boot parameter; wherein the first boot parameter is used to specify a target memory address for storing a critical memory data flag, the second boot parameter is used to indicate whether to select to retain the critical memory data, and the third boot parameter is used to specify a preset magic number as the critical memory data flag; When detecting that the operating system is started, adding the preset magic number to the target memory address located in the system memory; During the operation of the operating system, determining whether the target software needs to resume operation after the kernel switch; If the target software needs to resume running after the kernel switch, the preset system tool is called to start the target process corresponding to the target software, and the preset magic number located at the target memory address is added to the process control block of the target process.
3. The process recovery method according to claim 2, characterized in that: The adding the preset magic number to the target memory address located in the system memory includes: A random number is generated by a true random function, and the generated random number is added to the target memory address located in the system memory as the preset magic number.
4. The process recovery method according to claim 2, characterized in that: The target process corresponding to the target software that needs to perform kernel switching is run, and context information of the target process is collected during the running process to obtain process context information, including: Dynamically injecting a target process corresponding to the target software that requires kernel switching through a system call mechanism, and running the target process; Context information of the target process during its execution is collected from a preset virtual file system to obtain process context information.
5. The process recovery method according to claim 4, characterized in that: After collecting the context information of the target process during its execution and obtaining the process context information, the method further includes: Saving the process context information and the data in the process control block to a disk in the form of an image file; the process context information includes a memory table and process tree information; The address and length of the key memory area occupied by the target process are recorded in the disk.
6. The process recovery method according to claim 5, characterized in that: The step of identifying the process control block based on the preset magic number in the target memory address when detecting that the new kernel is started includes: When it is detected that the new kernel is started, detecting a second boot parameter in the system startup boot parameter, and if the second boot parameter indicates that the critical memory data is selected to be retained, detecting a target memory address for storing a critical memory data flag, and reading the preset magic number from the target memory address; When the system memory is initialized, the preset magic number is used to traverse and detect data in the system memory to identify the process control block containing the preset magic number.
7. The process recovery method according to claim 6, characterized in that: The retaining the data in the process control block and the process context information in the system memory includes: Identify the memory data area used by the target process according to the process control block, retain the data in the memory data area, and initialize other memory areas except the memory data area; the memory data area includes the data in the process control block and the process context information.
8. The process recovery method according to claim 7, characterized in that: The reading of the process context information and the data in the process control block includes: Detecting whether the key memory area matches the memory data area based on the address and length of the key memory area recorded in the disk; If the critical memory area matches the memory data area, the process context information and the data in the process control block are read from the system memory.
9. The process recovery method according to claim 8, characterized in that: Also includes: If the critical memory area does not match the memory data area, the process context information and the data in the process control block stored in the disk are restored to the system memory, and the step of reading the process context information and the data in the process control block is triggered.
10. The process recovery method according to claim 5, characterized in that: The adding the preset magic number located at the target memory address into the process control block of the target process includes: Adding the preset magic number located at the target memory address to the process control block of the target process and the process control blocks of the child processes generated by the target process; Accordingly, the recovering of the target process in the new process based on the process context information and the data in the process control block includes: Creating a process tree based on the process tree information in the process context information; Based on the process context information and the data in the process control block, the target process and the child processes generated by the target process are restored on the process tree.
11. The process recovery method according to claim 10, characterized in that: After the target process and the child processes generated by the target process are restored on the process tree, the method further includes: The code of the target process is executed, and the command line parameters and environment variables of the target process are passed to switch the context of the new process to the context of the target process.
12. The process recovery method according to any one of claims 1 to 11, characterized in that: Before the new kernel is loaded into the preset memory space, the process further includes: Block all CPU logic cores except the default one; Correspondingly, after the new kernel is started, the following steps are also included: The other CPU logic cores are brought back online in sequence.
13. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the process recovery method according to any one of claims 1 to 12 when executing the computer program.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the process recovery method according to any one of claims 1 to 12.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the process recovery method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Method and device for automatically and quickly recovering process of computer operating system
CN114756355A
Fault recovery method based on embedded operating system
CN119248577A