Process monitoring method, system, terminal and storage medium

By creating the parent process and monitoring the child process when receiving the target child process creation instructions, and using shared files for status monitoring, the out-of-control problem caused by problems in the monitoring process itself is solved, and the stability of process monitoring and the continuous operation of the system is achieved.

CN111913851BActive Publication Date: 2024-11-22PING AN TECH (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010770178.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-31
Publication Date
2024-11-22
Estimated Expiration
2040-07-31

AI Technical Summary

Technical Problem

When existing monitoring processes fail, block or interrupt problems, it may cause the monitored process to be out of control, affecting system stability.

Method used

When receiving the target child process creation instruction, create the corresponding parent process, and create the target child process and monitor the child process based on the parent process. Write and read state data through shared files to ensure that the monitor child process is automatically converted to guardian Process, avoid process blocking or downtime caused by system resource release or conflict.

Benefits of technology

The stability of the monitoring service is achieved, preventing the process from being automatically shut down or blocked due to resource release or conflict, ensuring the continuity of the monitoring service, and automatically restarting when the target child process is abnormal, maintaining the stable operation of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111913851B_ABST
    Figure CN111913851B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of process monitoring, and discloses a process monitoring method, system, terminal and storage medium, wherein the method comprises: upon receiving a target child process creation instruction, creating a corresponding parent process; creating a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process; closing the parent process; controlling the target child process to write status data to a shared file according to a preset write strategy; controlling the first monitoring child process to read the latest written status data in the shared file according to a preset read strategy, and monitoring the target child process according to the status data. The present invention solves the problem that the monitored process is out of control due to problems in the existing monitoring process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of process monitoring, and in particular to a process monitoring method, system, terminal and computer-readable storage medium. Background Art

[0002] There are processes in the system that implement key tasks. These processes cannot crash, get blocked, or be interrupted. To avoid the impact of these situations, these processes are usually monitored through monitoring processes. Once these monitoring processes occur, they can promptly inform the system so that the system can restart these processes in time. However, if the monitoring process itself crashes, gets blocked, or is interrupted, it may lead to loss of control. Summary of the invention

[0003] The main purpose of the present invention is to propose a process monitoring method, system, terminal and computer-readable storage medium, aiming to solve the problem that problems in the existing monitoring process cause the monitored process to be out of control.

[0004] To achieve the above object, the present invention provides a process monitoring method, comprising the steps of:

[0005] When receiving the target child process creation instruction, create the corresponding parent process;

[0006] Create a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process;

[0007] Close the parent process;

[0008] Control the target child process to write status data to the shared file according to the preset writing strategy;

[0009] The first monitoring subprocess is controlled to read the latest written status data in the shared file according to a preset reading strategy, and the target subprocess is monitored according to the status data.

[0010] Optionally, the step of creating a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process includes:

[0011] Create shared files based on the parent process;

[0012] Creating a target child process corresponding to the instruction based on the parent process and generating a process identifier of the target child process, and injecting preset parameters corresponding to the target child process into the target child process;

[0013] A first monitoring subprocess is created based on the parent process, and preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess are injected into the first monitoring subprocess.

[0014] Optionally, upon receiving the target child process creation instruction, the step of creating a corresponding parent process includes:

[0015] When receiving the target child process creation instruction, determine whether there are idle process handle resources;

[0016] If so, create the corresponding parent process;

[0017] If not, at least one currently running process is closed to release the process handle resources, and a corresponding parent process is created.

[0018] Optionally, after the step of controlling the first monitoring subprocess to read the latest written status data in the shared file according to a preset reading strategy and monitoring the target subprocess according to the status data, the step further includes:

[0019] When the first monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess is controlled to restart the target subprocess, and a new process identifier of the target subprocess is generated, and the new process identifier of the target subprocess is injected into the first monitoring subprocess.

[0020] Optionally, after the step of creating a target child process corresponding to the instruction based on the parent process, generating a process identifier of the target child process, and injecting preset parameters corresponding to the target child process into the target child process, the step further includes:

[0021] Create a first monitoring subprocess and a second monitoring subprocess based on the parent process;

[0022] Injecting the preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess, and injecting the preset parameters corresponding to the second monitoring subprocess and the process identifier of the target subprocess into the second monitoring subprocess;

[0023] The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the state data comprises:

[0024] Control the first monitoring subprocess and the second monitoring subprocess to read the latest written status data from the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data respectively;

[0025] When the first monitoring subprocess monitors that the target subprocess is abnormal, the steps of controlling the first monitoring subprocess to restart the target subprocess, generating a new process identifier of the target subprocess, and injecting the new process identifier of the target subprocess into the first monitoring subprocess include:

[0026] When the first monitoring subprocess and / or the second monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess or the second monitoring subprocess is controlled to restart the target subprocess, and update the process identifier of the target subprocess, and inject the updated process identifier of the target subprocess into the first monitoring subprocess and the second monitoring subprocess.

[0027] Optionally, the step of controlling the first monitoring subprocess to read the latest written status data in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the status data includes:

[0028] Control the first monitoring subprocess to read the latest status data written in the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data, and control the first monitoring subprocess and the second monitoring subprocess to send heartbeat signals to each other at a first preset time interval;

[0029] The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy and monitoring the target subprocess according to the state data includes:

[0030] When the second monitoring sub-process does not receive the heartbeat signal sent by the first monitoring sub-process within a second preset time, the second monitoring sub-process is controlled to restart the first monitoring sub-process, and the second monitoring sub-process is controlled to read the latest written status data in the shared file according to a preset reading strategy, and monitor the target sub-process according to the status data, wherein the second preset time is greater than the first preset time.

[0031] Optionally, after the step of controlling the first monitoring subprocess to read the latest written status data in the shared file according to a preset reading strategy and monitoring the target subprocess according to the status data, the step further includes:

[0032] When the first monitoring subprocess does not receive the heartbeat signal sent by the second monitoring subprocess within a second preset time, the first monitoring subprocess is controlled to restart the second monitoring subprocess.

[0033] To achieve the above object, the present invention further provides a process monitoring system, the system comprising:

[0034] A first creation module, used to create a corresponding parent process upon receiving a target child process creation instruction;

[0035] A second creation module, used to create a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process;

[0036] Shutdown module, used to shut down the parent process;

[0037] A writing module, used to control the target child process to write status data to a shared file according to a preset writing strategy;

[0038] The reading module is used to control the first monitoring sub-process to read the latest state data written in the shared file according to a preset reading strategy, and monitor the target sub-process according to the state data.

[0039] To achieve the above objectives, the present invention also provides a terminal, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the process monitoring method described above when executed by the processor.

[0040] To achieve the above object, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the process monitoring method described above are implemented.

[0041] The present invention proposes a process monitoring method, terminal and computer-readable storage medium, which creates a corresponding parent process upon receiving a target child process creation instruction; creates a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process; closes the parent process; controls the target child process to write status data to the shared file according to a preset write strategy; controls the first monitoring child process to read the latest status data written in the shared file according to a preset read strategy, and monitors the target child process according to the status data. After closing the parent process, the first monitoring child process is automatically converted into a daemon process, so that the first monitoring child process converted into a daemon process will not be automatically closed when the system needs to release some process resources, and will not cause the process to be blocked or downtime due to resource conflicts in the system, thereby making the monitoring service itself more stable.

[0042] At the same time, since the target sub-process and the first monitoring sub-process are both created based on the same parent process, the underlying codes corresponding to the target sub-process and the first monitoring sub-process belong to the same set of underlying codes. Therefore, during the business migration corresponding to the target sub-process, only one migration is required, that is, migrating a set of underlying codes corresponding to the target sub-process and the first monitoring sub-process, so that the first monitoring sub-process can continue to monitor the target sub-process. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 It is a schematic diagram of the structure of the hardware operating environment involved in the embodiment of the present invention;

[0044] Figure 2 It is a flowchart of the first embodiment of the process monitoring method of the present invention;

[0045] Figure 3 This is a detailed flow chart of step S20 in the first embodiment of the process monitoring method of the present invention;

[0046] Figure 4 It is a flow chart of the second embodiment of the process monitoring method of the present invention;

[0047] Figure 5 It is a flowchart of a third embodiment of the process monitoring method of the present invention;

[0048] Figure 6 A schematic diagram of a process flow chart of a fourth embodiment of a process monitoring method of the present invention;

[0049] Figure 7 Schematic diagram of the functional modules of the process monitoring system of the present invention.

[0050] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0051] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0052] Please refer to Figure 1 , Figure 1 Schematic diagram of the hardware structure of the terminal provided in each embodiment of the present invention. The terminal includes components such as a communication module 01, a memory 02 and a processor 03. Those skilled in the art can understand that Figure 1 The terminal shown in the figure may also include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. The processor 03 is connected to the memory 02 and the communication module 01 respectively, and the memory 02 stores a computer program, which is executed by the processor 03 at the same time.

[0053] The communication module 01 can be connected to an external device through a network. The communication module 01 can receive data sent by an external device, and can also send data, instructions and information to the external device, which can be an electronic device such as a mobile phone, a tablet computer, a laptop computer and a desktop computer.

[0054] The memory 02 can be used to store software programs and various data. The memory 02 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (a target child process corresponding to the instruction created based on the parent process, a first monitoring child process and a shared file), etc.; the data storage area can store data or information created according to the use of the terminal, etc. In addition, the memory 02 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0055] Processor 03 is the control center of the terminal. It uses various interfaces and lines to connect various parts of the entire terminal. It executes various functions of the terminal and processes data by running or executing software programs and / or modules stored in memory 02, and calling data stored in memory 02, so as to monitor the terminal as a whole. Processor 03 may include one or more processing units; preferably, processor 03 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application programs, etc., and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into processor 03.

[0056] although Figure 1 Although not shown, the terminal may further include a circuit control module, which is used to connect to the mains to achieve power control and ensure the normal operation of other components.

[0057] Those skilled in the art will understand that Figure 1 The terminal structure shown in the figure does not constitute a limitation on the terminal, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0058] Based on the above hardware structure, various embodiments of the method of the present invention are proposed.

[0059] Reference Figure 2 In a first embodiment of the process monitoring method of the present invention, the process monitoring method comprises the steps of:

[0060] Step S10, upon receiving the target child process creation instruction, create the corresponding parent process;

[0061] In this solution, when a task or business needs to be executed, a process for executing the task or business will be created, so when a task or business needs to be executed, a target child process creation instruction will be received. When the target child process creation instruction is received, a parent process will be created first.

[0062] Step S20, creating a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process;

[0063] Then, based on the created parent process, create the target child process, monitoring child process and shared file. The target child process is used to execute various tasks. The monitoring child process is used to monitor the running status of the target child process. The shared file is used to store the status data of the target child process.

[0064] For details, please refer to the process of creating the target child process, the first monitoring child process and the shared file based on the parent process. Figure 3 Based on the above embodiment, step S20 includes:

[0065] Step S21, creating a shared file based on the parent process;

[0066] First, create a shared file based on the created parent process. To ensure that all child processes under the same parent process can access the shared file, you can set the read and write permissions of all child processes under the same parent process. For example, set the read and write permissions of the shared file to 777. You can also set the target child process to have write permissions for the shared file, and the first monitoring child process to have read permissions.

[0067] Step S22, creating a target child process corresponding to the instruction based on the parent process and generating a process identifier of the target child process, and injecting preset parameters corresponding to the target child process into the target child process;

[0068] Then, the target child process is created based on the created parent process. Specifically, the target child process is created by calling the parent process to execute the fork() function. After executing the fork() function, a non-negative integer value will be returned. The non-negative integer value is the process ID of the created target child process. Then, the preset parameters corresponding to the target child process are injected into the created target child process, so that the target child process starts normally, executes tasks, and feedbacks the status according to the injected preset parameters. The preset parameters corresponding to the target child process refer to the parameters required for the normal startup and normal execution of tasks of the target child process, including startup parameters and running parameters.

[0069] Step S23: Create a first monitoring subprocess based on the parent process, and inject preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess.

[0070] After the target child process is created and the corresponding parameters are injected, the first monitoring child process is created again by calling the parent process to execute the fork() function, and then the preset parameters corresponding to the first monitoring child process and the process ID of the target child process are injected into the created first monitoring child process, so that the first monitoring child process is normally started according to the injected preset parameters and the process ID of the target child process and performs the monitoring task on the target child process. The preset parameters corresponding to the monitoring child process refer to the parameters required for the normal startup and normal execution of monitoring of the monitoring child process, including startup parameters and monitoring operation parameters.

[0071] It should be noted that step S22 is preferably executed before step S23, and the relative order between executing step S21 and executing step S22 and step S23 is not limited, that is, step S21 can be executed first, and then step S22 and step S23 can be executed in sequence as described in this embodiment, or step S22 and step S23 can be executed first in sequence and then step S21, or step S22 can be executed first, then step S21, and finally step S23.

[0072] Step S30, closing the parent process;

[0073] After successfully creating the target child process, monitoring child process and shared files, the parent process will be closed. Due to the closure of the parent process, the target child process and monitoring child process become resident process types, which will be started when the system starts and closed when the system shuts down. They will not be automatically closed when the system needs to release some process resources, nor will the process be blocked or down due to resource conflicts in the system.

[0074] Step S40, controlling the target child process to write the status data to the shared file according to a preset writing strategy;

[0075] After closing the parent process, the target child process is controlled to write its own status data into the shared file according to the preset write strategy. Specifically, when the preset write strategy is real-time writing, the target child process will be controlled to write its own status data into the shared file in real time. When the preset write strategy is to write at preset time intervals, the target child process will be controlled to write its own status data into the shared file at preset time intervals, for example, every 1 minute, the target child process will be controlled to write its own status data into the shared file when a task is completed. When the preset write strategy is to write at the end of each task, the target child process will be controlled to write its own status data into the shared file when a task is completed.

[0076] Step S50, controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the state data.

[0077] After closing the parent process, the first monitoring child process will be controlled to read the latest status data written by the target child process from the shared file according to the preset reading strategy. When the preset reading strategy is real-time reading, the first monitoring child process will be controlled to read the latest status data written by the target child process from the shared file in real time. When the preset reading strategy is to read at preset time intervals, the first monitoring child process will be controlled to read the latest status data written by the target child process from the shared file at preset time intervals, for example, every 1 minute, to read the latest status data written by the target child process from the shared file.

[0078] After controlling the first monitoring subprocess to read the latest written status data from the shared file, the monitoring subprocess will be controlled to monitor the target subprocess according to the latest written status data read, and determine the state of the monitored target subprocess, which may include initialization state, loading state, normal operation state, normal exit state or abnormal state, etc., and the type of state is not limited here. The status data corresponding to each state can be represented by different identifiers. For example, the target subprocess uses the number 0 to represent the initialization state, the number 1 to represent normal operation, the number 2 to represent the loading state, the number 4 to represent the normal exit state, and the number 9 to identify the abnormal state. After the first monitoring subprocess reads the latest written status data, the state of the currently monitored target subprocess can be known. For example, if the latest written status data read is 1, the first monitoring subprocess can know that the state of the target subprocess is in normal operation. If the latest written status data read is 9, the first monitoring subprocess can know that the state of the target subprocess is abnormal.

[0079] It should be noted that there may be certain reasons that cause the target sub-process to become abnormal and cause the target sub-process to be unable to write its own status data to the shared file. If the status data last written in the shared file before the target sub-process becomes abnormal is a normal operating status, the first monitoring sub-process reads the latest written data in the shared file and may mistakenly believe that the target sub-process is still in a normal operating state. To prevent this situation from happening, the first monitoring sub-process will also read the writing time of the latest written data when reading the latest written data from the shared file, and determine whether the difference between the writing time of the latest written data and the current time is greater than or equal to a preset threshold. If it is greater than or equal to the preset threshold, it is directly determined that the target sub-process is in an abnormal state. If it is less than the preset threshold, the status of the target sub-process is determined based on the latest status data read.

[0080] When the preset write strategy of the target subprocess is to write status data after each task is executed, the target subprocess may fail to write its own status data to the shared file for a long time due to the long task completion time, so that the difference between the time when the first monitoring subprocess reads the latest written data from the shared file and the write time corresponding to the latest status data written in the shared file is greater than the preset threshold. If the strategy of judging the target subprocess abnormality according to exceeding the preset threshold is used, the first monitoring subprocess will mistakenly judge the status of the target subprocess and mistakenly restart the target subprocess, causing the task being executed by the target subprocess to be interrupted. In order to avoid this problem, if the difference between the time when the first monitoring subprocess reads the latest written data from the shared file and the write time corresponding to the latest status data written in the shared file is greater than the preset threshold, the first monitoring subprocess will be controlled to send a heartbeat signal to the target subprocess at regular intervals. If the target subprocess receives the heartbeat signal and is normal, it will feed back a heartbeat response to the first monitoring subprocess within a certain period of time. Thus, in the scenario where the difference between the time when the first monitoring subprocess reads the latest written data from the shared file and the write time corresponding to the latest written status data in the shared file is greater than the preset threshold, the target subprocess can be confirmed to be still in a normal state based on the received heartbeat response, and will not be mistakenly determined to be in an abnormal state. In order to avoid this problem, if the target subprocess does not write status data to the shared file for more than a certain period of time, the target subprocess can also be controlled to actively send a heartbeat signal to the monitoring subprocess, so that the monitoring subprocess can confirm that the target subprocess is still executing the task and is in a normal state.

[0081] This example creates a corresponding parent process upon receiving a target child process creation instruction; creates a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process; closes the parent process; controls the target child process to write status data to the shared file according to a preset write strategy; controls the first monitoring child process to read the latest status data written in the shared file according to a preset read strategy, and monitors the target child process according to the status data. After closing the parent process, the first monitoring child process is automatically converted into a daemon process, so that the first monitoring child process converted into a daemon process will not be automatically closed when the system needs to release some process resources, and will not be blocked or downtime due to resource conflicts in the system, thereby making the monitoring service itself more stable.

[0082] At the same time, since the target sub-process and the first monitoring sub-process are both created based on the same parent process, the underlying codes corresponding to the target sub-process and the first monitoring sub-process belong to the same set of underlying codes. Therefore, during the business migration corresponding to the target sub-process, only one migration is required, that is, migrating a set of underlying codes corresponding to the target sub-process and the first monitoring sub-process, so that the first monitoring sub-process can continue to monitor the target sub-process.

[0083] For further information, please refer to Figure 4 , Figure 4 A second embodiment of the process monitoring method of the present application is proposed based on the first embodiment of the process monitoring method of the present application. In this embodiment, step S10 includes:

[0084] Step S11, upon receiving the target child process creation instruction, determine whether there are idle process handle resources; if so, execute step S12; if not, execute step S13;

[0085] Step S12, creating a corresponding parent process;

[0086] Step S13, closing at least one currently running process to release process handle resources, and creating a corresponding parent process.

[0087] In this embodiment, since creating a process requires consuming the system's process handle resources, in order to successfully create a parent process, a target child process, a monitoring child process, etc., when receiving a target child process creation instruction, it will first determine whether the system has idle process handle resources. If so, the corresponding parent process will be created directly. If there are no idle process handle resources, at least one currently running process will be closed to release the occupied process handle resources, and then the parent process will be created using the released process handle resources.

[0088] It should be noted that when closing the currently running process, the process with the lowest importance level may be closed first according to the preset importance levels corresponding to the currently running processes, that is, the unimportant processes may be closed.

[0089] This embodiment determines whether the system has idle process handle resources for creating the parent process, the target child process and the first monitoring child process before creating the parent process, the target child process and the first monitoring child process, thereby avoiding the failure of process creation due to the lack of process handle resources, making the process creation process take a long time, and improving the efficiency and success rate of process creation.

[0090] For further information, please refer to Figure 5 , Figure 5A third embodiment of the process monitoring method of the present application is proposed based on the first and second embodiments of the process monitoring method of the present application. In this embodiment, after step S50, the following steps are included:

[0091] Step S60, when the first monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess is controlled to restart the target subprocess, and a new process identifier of the target subprocess is generated, and the new process identifier of the target subprocess is injected into the first monitoring subprocess.

[0092] In this embodiment, after controlling the first monitoring sub-process to determine that the target sub-process is in an abnormal state according to the read status data, the first monitoring sub-process will be controlled to call the kill() function according to the process ID of the injected target sub-process to close the target sub-process corresponding to the process ID, and restart the target sub-process so that the target sub-process can run normally and continue to execute tasks. At the same time, corresponding to the restarted target sub-process, a new process ID will be generated for the target sub-process, and then the new process ID will be injected into the first monitoring sub-process to replace the process ID of the target sub-process originally injected, so that the first monitoring sub-process can continue to monitor the restarted target sub-process.

[0093] This embodiment restarts the target subprocess immediately after confirming that an abnormality exists in the target subprocess, so that the target subprocess can continue to execute the task.

[0094] For further information, please refer to Figure 6 , Figure 6 A fourth embodiment of the process monitoring method of the present application is proposed based on the first embodiment, the second embodiment and the third embodiment of the process monitoring method of the present application. In this embodiment, after step S22, the following steps are further included:

[0095] Step S24, creating a first monitoring subprocess and a second monitoring subprocess based on the parent process;

[0096] Step S25, injecting the preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess, and injecting the preset parameters corresponding to the second monitoring subprocess and the process identifier of the target subprocess into the second monitoring subprocess;

[0097] Step S50 includes:

[0098] Step S51, controlling the first monitoring subprocess and the second monitoring subprocess to read the latest written status data from the shared file according to a preset reading strategy, and monitoring the target subprocess according to the status data;

[0099] Step S60 includes:

[0100] Step S61, when the first monitoring subprocess and / or the second monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess or the second monitoring subprocess is controlled to restart the target subprocess, and the process identifier of the target subprocess is updated, and the updated process identifier of the target subprocess is injected into the first monitoring subprocess and the second monitoring subprocess.

[0101] In this embodiment, after the target child process is created and the corresponding parameters are injected, two monitoring child processes, namely the first monitoring child process and the second monitoring child process, are created by calling the parent process to execute the fork() function. Then, the preset parameters corresponding to the first monitoring child process and the process identifier of the target child process are injected into the created first monitoring child process, and the preset parameters corresponding to the second monitoring child process and the process identifier of the target child process are injected into the created second monitoring child process. In this way, both the first monitoring child process and the second monitoring child process are started normally according to the injected corresponding preset parameters and the process identifier of the target child process, and the monitoring tasks are performed on the target child process.

[0102] After closing the parent process, the first monitoring subprocess and the second monitoring subprocess will be controlled to read the latest status data written by the target subprocess from the shared file according to the preset reading strategy. When the preset reading strategy is real-time reading, the first monitoring subprocess and the second monitoring subprocess will be controlled to read the latest status data written by the target subprocess from the shared file in real time. When the preset reading strategy is to read at preset time intervals, the first monitoring subprocess and the second monitoring subprocess will be controlled to read the latest status data written by the target subprocess from the shared file at preset time intervals, for example, every 1 minute, to read the latest status data written by the target subprocess from the shared file.

[0103] After controlling the first monitoring sub-process and the second monitoring sub-process to read the latest written status data from the shared file, the first monitoring sub-process and the second monitoring sub-process will be controlled to determine the status of the monitored target sub-process based on the latest written status data read. The status may include initialization status, loading status, normal operating status, normal exit status or abnormal status, etc. The type of status is not limited here.

[0104] When any one of the first monitoring sub-process and the second monitoring sub-process determines that the state of the target sub-process is abnormal, the first monitoring sub-process or the second monitoring sub-process will be controlled to call the kill() function according to the process ID of the injected target sub-process to close the target sub-process corresponding to the process ID, and restart the target sub-process so that the target sub-process can run normally and continue to execute tasks. At the same time, corresponding to the restarted target sub-process, a new process ID of the target sub-process will be reallocated, and then the updated process ID will be injected into the first monitoring sub-process and the second monitoring sub-process, replacing the process ID of the target sub-process originally injected, so that the first monitoring sub-process and the second monitoring sub-process can continue to monitor the restarted target sub-process.

[0105] It should be noted that the step of executing controlling the first monitoring subprocess or the second monitoring subprocess to restart the target subprocess can specifically be to first control the first monitoring subprocess to restart the target subprocess, and if the first monitoring subprocess fails to restart the target subprocess, then control the second monitoring subprocess to restart the target subprocess.

[0106] This embodiment establishes two monitoring sub-processes to monitor the status of the same target sub-process at the same time, thereby preventing the target sub-process from being in a monitoring out-of-control state due to a problem in the only monitoring sub-process.

[0107] Further, according to the above-mentioned embodiment of the process monitoring method of the present application, a fifth embodiment of the process monitoring method of the present application is proposed. In this embodiment, step S50 includes:

[0108] Step S52, controlling the first monitoring subprocess to read the latest status data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the status data, while controlling the first monitoring subprocess and the second monitoring subprocess to send heartbeat signals to each other at a first preset time interval;

[0109] Step S50 includes:

[0110] Step S70, when the second monitoring subprocess does not receive the heartbeat signal sent by the first monitoring subprocess for more than a second preset time, control the second monitoring subprocess to restart the first monitoring subprocess, and control the second monitoring subprocess to read the latest written status data in the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data;

[0111] Step S80, when the first monitoring subprocess does not receive the heartbeat signal sent by the second monitoring subprocess for more than a second preset time, control the first monitoring subprocess to restart the second monitoring subprocess.

[0112] In this embodiment, although two monitoring sub-processes, namely the first monitoring sub-process and the second monitoring sub-process, are created based on the parent process, after the parent process is closed, only the first monitoring sub-process of the two created monitoring sub-processes will be controlled to read the latest status data written by the target sub-process from the shared file according to the preset reading strategy, and confirm the status of the target sub-process based on the read status data. At the same time, the first monitoring sub-process and the second monitoring sub-process will be controlled to send heartbeat signals to each other at every first preset time. Both parties judge whether the other party is in an abnormal state by whether they have not received the heartbeat signal sent by the other party for more than the second preset time. When the second monitoring sub-process does not receive the heartbeat signal sent by the first monitoring sub-process for more than the second preset time, , it will confirm that the first monitoring subprocess is in an abnormal state, which means that the target subprocess is in a monitoring out-of-control state. At this time, the second monitoring subprocess will be controlled to start the task of reading the status data, that is, read the latest status data written in the shared file according to the preset reading strategy, and monitor the target subprocess according to the status data. At the same time, the second monitoring subprocess is controlled to restart the first monitoring subprocess. Since the second monitoring subprocess is already executing the task of reading the status data, the restarted first monitoring subprocess will not resume the task of reading the status data, but will only resume the heartbeat connection established to send a heartbeat signal to the second monitoring subprocess every first preset time to monitor whether the second monitoring subprocess is in a normal operating state. If the first monitoring subprocess determines that the second monitoring subprocess is abnormal later, the first monitoring subprocess will start the task of reading the status data again and restart the second monitoring subprocess. The restarted second monitoring subprocess will not start the task of reading the status data either.

[0113] When the first monitoring subprocess does not receive a heartbeat signal sent by the second monitoring subprocess through the established heartbeat connection for more than a second preset time, it will be confirmed that the second monitoring subprocess is in an abnormal state, and the first monitoring subprocess will be controlled to restart the second monitoring subprocess.

[0114] It should be noted that before controlling any one of the two monitoring sub-processes to restart the other monitoring sub-process, it will first be determined whether the monitoring sub-process currently executing the task of reading the latest status data written in the shared file according to the preset reading strategy and monitoring the target sub-process according to the status data is the monitoring sub-process to be restarted. If not, it means that the task of reading the latest status data written in the shared file according to the preset reading strategy and monitoring the target sub-process according to the status data is executed by the other monitoring sub-process of the two monitoring sub-processes. The monitoring sub-process to be restarted is then restarted by the other monitoring sub-process. After the restart, the monitoring sub-process resumes the task of sending heartbeat signals to the other monitoring sub-process, and the other A monitoring sub-process still continues to execute the task of reading the latest status data written in the shared file according to the preset read strategy, and monitoring the target sub-process according to the status data; if so, it means that the task of reading the latest status data written in the shared file according to the preset read strategy, and monitoring the target sub-process according to the status data is the monitoring sub-process to be restarted, and another monitoring sub-process will be switched to execute the task of reading the latest status data written in the shared file according to the preset read strategy, and monitoring the target sub-process according to the status data, and control the other monitoring sub-process to restart the monitoring sub-process to be restarted. After the restart, the monitoring sub-process only resumes the task of sending heartbeat signals to another monitoring sub-process.

[0115] This embodiment creates two monitoring subprocesses, and only one monitoring subprocess executes the reading of status data at the same time. The heartbeat connection established between the two monitoring subprocesses can monitor each other's status. When the monitoring subprocess currently executing the reading of status data task is abnormal, the other monitoring subprocess executes the reading of status data task, thereby ensuring that the reading of status data task will not be interrupted, so that the target subprocess will not be out of control. In addition, sending a heartbeat signal requires fewer system resources than reading status data, so compared with two monitoring subprocesses executing the reading of status data task at the same time, the two monitoring subprocesses take fewer system resources when executing the reading of status data task in turn.

[0116] See also Figure 7 The present invention also provides a process monitoring system, comprising:

[0117] A first creation module 10 is used to create a corresponding parent process when receiving a target child process creation instruction;

[0118] A second creation module 20, used to create a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process;

[0119] A closing module 30 is used to close the parent process;

[0120] A writing module 40, used to control the target child process to write status data to the shared file according to a preset writing strategy;

[0121] The reading module 50 is used to control the first monitoring sub-process to read the latest state data written in the shared file according to a preset reading strategy, and monitor the target sub-process according to the state data.

[0122] Further, the second creation module 20 includes:

[0123] A first creation submodule 21, used to create a shared file based on a parent process;

[0124] A second creation submodule 22 is used to create a target child process corresponding to the instruction based on the parent process and generate a process identifier of the target child process, and inject preset parameters corresponding to the target child process into the target child process;

[0125] The third creation submodule 23 is used to create a first monitoring subprocess based on the parent process, and inject preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess.

[0126] Furthermore, the first creation module 10 also includes:

[0127] The judging submodule 11 is used to judge whether there are idle process handle resources when receiving the target child process creation instruction; if not, call the fourth creating submodule 12 to perform corresponding operations; if yes, call the closing submodule 13 to perform corresponding operations;

[0128] The fourth creation submodule 12 is used to create a corresponding parent process;

[0129] The closing submodule 13 is used to close at least one currently running process to release process handle resources, and create a corresponding parent process.

[0130] Further, the state of the target subprocess includes an abnormal state, and the process monitoring system further includes:

[0131] The first restart module 60 is used to control the first monitoring subprocess to restart the target subprocess when the first monitoring subprocess monitors that the target subprocess is abnormal, generate a new process identifier of the target subprocess, and inject the new process identifier of the target subprocess into the first monitoring subprocess.

[0132] Furthermore, the second creation module 20 also includes:

[0133] A fifth creation submodule 14, configured to create a first monitoring subprocess and a second monitoring subprocess based on the parent process;

[0134] The injection submodule 15 is used to inject the preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess, and to inject the preset parameters corresponding to the second monitoring subprocess and the process identifier of the target subprocess into the second monitoring subprocess;

[0135] The reading module 50 comprises:

[0136] A first reading submodule is used to control the first monitoring subprocess and the second monitoring subprocess to read the latest written status data from the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data;

[0137] The first restart module 60 includes:

[0138] The restart submodule 61 is used to control the first monitoring subprocess or the second monitoring subprocess to restart the target subprocess when the first monitoring subprocess and / or the second monitoring subprocess monitors an abnormality in the target subprocess, and update the process identifier of the target subprocess, and inject the updated process identifier of the target subprocess into the first monitoring subprocess and the second monitoring subprocess.

[0139] Further, the reading module 50 includes:

[0140] A second reading submodule 52 is used to control the first monitoring subprocess to read the latest status data written in the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data, and control the first monitoring subprocess and the second monitoring subprocess to send heartbeat signals to each other at a first preset time interval;

[0141] The process monitoring system also includes:

[0142] The second restart module 70 controls the second monitoring subprocess to restart the first monitoring subprocess when the second monitoring subprocess does not receive the heartbeat signal sent by the first monitoring subprocess within a second preset time, and controls the second monitoring subprocess to read the latest written status data in the shared file according to a preset reading strategy, and monitors the target subprocess according to the status data, wherein the second preset time is greater than the first preset time.

[0143] Furthermore, the process monitoring system further includes:

[0144] The third restart module 80 is used to control the first monitoring subprocess to restart the second monitoring subprocess when the first monitoring subprocess does not receive the heartbeat signal sent by the second monitoring subprocess for more than a second preset time.

[0145] The present invention also provides a computer-readable storage medium on which a computer program is stored. The computer-readable storage medium may be Figure 1The memory 02 in the terminal may also be at least one of a ROM (Read-Only Memory) / RAM (Random Access Memory), a magnetic disk, and an optical disk. The computer-readable storage medium includes some information for enabling the terminal to execute the methods described in the various embodiments of the present invention.

[0146] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0147] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0148] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0149] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A process monitoring method, characterized in that: Includes steps: When receiving the target child process creation instruction, create the corresponding parent process; Create a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process; Close the parent process; Control the target child process to write status data to the shared file according to the preset writing strategy; Controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the state data; The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy and monitoring the target subprocess according to the state data further includes: When the first monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess is controlled to restart the target subprocess, and a new process identifier of the target subprocess is generated, and the new process identifier of the target subprocess is injected into the first monitoring subprocess; The step of creating a target child process corresponding to the instruction based on the parent process, generating a process identifier of the target child process, and injecting preset parameters corresponding to the target child process into the target child process further includes: Create a first monitoring subprocess and a second monitoring subprocess based on the parent process; Injecting the preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess into the first monitoring subprocess, and injecting the preset parameters corresponding to the second monitoring subprocess and the process identifier of the target subprocess into the second monitoring subprocess; The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the state data comprises: Control the first monitoring subprocess and the second monitoring subprocess to read the latest written status data from the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data respectively; When the first monitoring subprocess monitors that the target subprocess is abnormal, the steps of controlling the first monitoring subprocess to restart the target subprocess, generating a new process identifier of the target subprocess, and injecting the new process identifier of the target subprocess into the first monitoring subprocess include: When the first monitoring subprocess and / or the second monitoring subprocess monitors that the target subprocess is abnormal, the first monitoring subprocess or the second monitoring subprocess is controlled to restart the target subprocess, and update the process identifier of the target subprocess, and inject the updated process identifier of the target subprocess into the first monitoring subprocess and the second monitoring subprocess.

2. The process monitoring method according to claim 1, characterized in that: The step of creating a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process includes: Create shared files based on the parent process; Creating a target child process corresponding to the instruction based on the parent process and generating a process identifier of the target child process, and injecting preset parameters corresponding to the target child process into the target child process; A first monitoring subprocess is created based on the parent process, and preset parameters corresponding to the first monitoring subprocess and the process identifier of the target subprocess are injected into the first monitoring subprocess.

3. The process monitoring method according to claim 2, characterized in that: When receiving the target child process creation instruction, the step of creating the corresponding parent process includes: When receiving the target child process creation instruction, determine whether there are idle process handle resources; If so, create the corresponding parent process; If not, at least one currently running process is closed to release the process handle resources, and a corresponding parent process is created.

4. The process monitoring method according to claim 1, characterized in that: The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy, and monitoring the target subprocess according to the state data comprises: Control the first monitoring subprocess to read the latest status data written in the shared file according to a preset reading strategy, and monitor the target subprocess according to the status data, and control the first monitoring subprocess and the second monitoring subprocess to send heartbeat signals to each other at a first preset time interval; The step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to a preset reading strategy and monitoring the target subprocess according to the state data includes: When the second monitoring sub-process does not receive the heartbeat signal sent by the first monitoring sub-process within a second preset time, the second monitoring sub-process is controlled to restart the first monitoring sub-process, and the second monitoring sub-process is controlled to read the latest written status data in the shared file according to a preset reading strategy, and monitor the target sub-process according to the status data, wherein the second preset time is greater than the first preset time.

5. The process monitoring method according to claim 4, characterized in that: After the step of controlling the first monitoring subprocess to read the latest state data written in the shared file according to the preset reading strategy and monitoring the target subprocess according to the state data, the following step further includes: When the first monitoring subprocess does not receive the heartbeat signal sent by the second monitoring subprocess within a second preset time, the first monitoring subprocess is controlled to restart the second monitoring subprocess.

6. A process monitoring system, characterized in that: The process monitoring system is implemented by the process monitoring method according to claim 1, and the process monitoring system comprises: A first creation module, used to create a corresponding parent process upon receiving a target child process creation instruction; A second creation module, used to create a target child process, a first monitoring child process and a shared file corresponding to the instruction based on the parent process; Shutdown module, used to shut down the parent process; A writing module, used to control the target child process to write status data to a shared file according to a preset writing strategy; The reading module is used to control the first monitoring sub-process to read the latest state data written in the shared file according to a preset reading strategy, and monitor the target sub-process according to the state data.

7. A terminal, characterized in that: The terminal includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the process monitoring method according to any one of claims 1 to 5 when executed by the processor.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the process monitoring method according to any one of claims 1 to 5 are implemented.