CN114461486A - Process management method, apparatus and storage medium - Google Patents

Process management method, apparatus and storage medium Download PDF

Info

Publication number
CN114461486A
CN114461486A CN202111608525.XA CN202111608525A CN114461486A CN 114461486 A CN114461486 A CN 114461486A CN 202111608525 A CN202111608525 A CN 202111608525A CN 114461486 A CN114461486 A CN 114461486A
Authority
CN
China
Prior art keywords
monitored
restart
preset
linked list
running
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111608525.XA
Other languages
Chinese (zh)
Inventor
郑伟强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ruijie Networks Co Ltd
Original Assignee
Ruijie Networks Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ruijie Networks Co Ltd filed Critical Ruijie Networks Co Ltd
Priority to CN202111608525.XA priority Critical patent/CN114461486A/en
Publication of CN114461486A publication Critical patent/CN114461486A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3089Monitoring arrangements determined by the means or processing involved in sensing the monitored data, e.g. interfaces, connectors, sensors, probes, agents

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a process management method, a device and a storage medium, wherein the method comprises the following steps: a daemon process in a network operating system acquires a target monitoring message sent by a kernel, and the message can indicate the running state of a process to be monitored. If the target monitoring message indicates that the process to be monitored is exited, the daemon process further controls the running mode of the process to be monitored. In the method, the kernel can monitor the running state of the process to be monitored in the network operating system in real time and send the monitoring message to the daemon process, so that the daemon process can also know the running state of the process in real time and further control the running mode of the process to be monitored. Compared with the method that the daemon monitors the running state of the process in a polling mode, the daemon can immediately monitor the abnormal exit of the process by receiving the monitoring message sent by the kernel in real time, namely, the delay of judging the abnormal exit of the process is shortened.

Description

Process management method, apparatus and storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a process management method, device, and storage medium.
Background
The normal work of the whole system can be ensured through the cooperative work of each process in a network operating system such as Linux. In the actual running process of the network operating system, the process may be abnormally exited, and especially when an important process in the network operating system is abnormally exited, if the core process is not controlled to restart in time, the whole network operating system may be paralyzed.
In the prior art, the daemon running in the operating system can monitor the running state of the process in the system, and when the process exits abnormally, the process can be further controlled to restart. For many processes needing to be monitored in a network operating system, a daemon process often needs to sequentially judge the running states of different processes in a polling mode, so that the judgment of abnormal exit of the processes has delay.
Therefore, how to reduce the delay of the process abnormal exit judgment becomes a problem to be solved urgently.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, and a storage medium for process management, so as to reduce the delay of process exception exit determination.
In a first aspect, an embodiment of the present invention provides a process management method, applied to a daemon process, including:
acquiring a target monitoring message which is sent by a kernel and indicates the running state of a process to be monitored;
if the target monitoring message indicates that the process to be monitored is quitted, the running mode of the process to be monitored is determined again;
and controlling the running of the process to be monitored according to the running mode.
In a second aspect, an embodiment of the present invention provides a process management device, including:
the acquisition module is used for acquiring a target monitoring message which is sent by a kernel and indicates the running state of a process to be monitored;
the determining module is used for re-determining the running mode of the process to be monitored if the target monitoring message indicates that the process to be monitored is quitted;
and the control module is used for controlling the running of the process to be monitored according to the running mode.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, where the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the method for process management in the first aspect is implemented. The electronic device may also include a communication interface for communicating with other devices or a communication network.
In a fourth aspect, an embodiment of the present invention provides a non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to implement at least the process management method according to the first aspect.
In the process management method provided by the embodiment of the invention, the daemon process in the network operating system acquires the target monitoring message sent by the kernel, and the message can indicate the running state of the process to be monitored, namely the process to be monitored is in a starting state or an exiting state. If the target monitoring message indicates that the process to be monitored is quitted, the daemon process determines the running mode of the process to be monitored and controls the process to be monitored according to the running mode.
In the method, the kernel can monitor the running state of the process to be monitored in the network operating system in real time and notify the daemon process of the monitoring information in real time, so that the daemon process can also know the running state of the process to be monitored in time, and further control the running mode of the process to be monitored according to the information, thereby improving the instantaneity of the control of the process to be monitored. Meanwhile, compared with the method that the daemon process monitors the running state of the process in a polling mode, the daemon process directly monitors the running state of the process according to the monitoring message, so that the daemon process can more quickly monitor the exit of the process, and the delay of exit judgment of the process is reduced. Compared with a polling monitoring mode, the method adopting the message receiving mode can also save the system resources of the network operating system.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a flowchart of a process management method according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a process management process according to an embodiment of the present invention;
FIG. 3 is a flowchart of another process management method according to an embodiment of the present invention;
FIG. 4 is a signaling diagram of a process management method corresponding to the embodiment shown in FIG. 3;
fig. 5 is a flowchart illustrating a daemon process controlling restart of a process to be monitored according to an embodiment of the present invention;
FIG. 6 is a flowchart of another process management method according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating a process management process corresponding to the embodiment shown in FIG. 6;
FIG. 8 is a signaling diagram of a process management procedure corresponding to the embodiment shown in FIG. 6;
fig. 9 is a schematic structural diagram of an electronic device corresponding to the process management method according to the embodiment of the present invention;
fig. 10 is a schematic structural diagram of another electronic device corresponding to the process management method according to the embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, and "a" and "an" generally include at least two, but do not exclude at least one, unless the context clearly dictates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the front and rear associated objects are in an "or" relationship.
The words "if," "if," as used herein may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a recognition," depending on the context. Similarly, the phrases "if determined" or "if identified (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when identified (a stated condition or event)" or "in response to an identification (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a good or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such good or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a commodity or system that includes the element.
Some embodiments of the invention are described in detail below with reference to the accompanying drawings. The features of the embodiments and examples described below may be combined with each other without conflict between the embodiments. In addition, the sequence of steps in each method embodiment described below is only an example and is not strictly limited.
Fig. 1 is a flowchart of a process management method according to an embodiment of the present invention. The process management method provided by the embodiment of the invention can be executed by a daemon process running in a user mode in a network operating system. The process management method may specifically include the steps of:
s101, acquiring a target monitoring message which is sent by a kernel and indicates the running state of the process to be monitored.
A network operating system, such as a Linux system, runs a plurality of processes, and according to actual requirements, a part of the processes can be used as processes to be monitored. Optionally, the process to be monitored may include a user process running in a user mode and/or a kernel process running in a kernel mode.
In the actual operation process, the operation state of the process to be monitored may change. Such as from the initiating state to the exiting state, or from the exiting state back to the initiating state, etc.
For the change of the running state of the process to be monitored, the kernel can acquire the change in real time, so that a target monitoring message is generated, and the target monitoring message is sent to the daemon process. The daemon process can also immediately know the change of the running state of the process to be monitored after receiving the message.
As can be seen from the above description, the running state of the process to be monitored can be notified to the daemon process by using the target monitoring message, that is, the inter-process communication is realized, and optionally, the monitoring message may be a netlink message corresponding to a netlink mechanism supported in the Linux system.
And S102, if the target monitoring message indicates that the process to be monitored is quitted, re-determining the running mode of the process to be monitored.
And S103, controlling the running of the process to be monitored according to the running mode.
Because the target monitoring message contains the identifier indicating the running state, the daemon process can determine whether the process to be monitored is in the starting state or the exiting state through the identifier.
If the target monitoring message received by the daemon process reflects that the process to be monitored is quitted, in order to ensure the normal operation of the system, the daemon process can redetermine the operation mode of the process to be monitored and control the operation of the process to be monitored according to the redetermined operation mode. Optionally, according to different importance degrees of the processes to be monitored or different reasons for quitting the processes to be monitored, the operation mode of the processes to be monitored, which is re-determined by the daemon process, may specifically include controlling the processes to be monitored to continue to be in a quit state or controlling the processes to be monitored to restart, and the like.
For example, when the importance degree of the process to be monitored is high, the exit of the process may affect the normal operation of the system, and even cause the system to be paralyzed, and in order to ensure the normal operation of the system, the daemon needs to control the restart of the process, that is, the operation mode of the daemon, which is determined again and is specific to the process to be monitored, is the restart mode of the process to be monitored. Optionally, the restarting manner may include restarting the process to be monitored after exiting for N seconds, that is, allowing the process to be monitored to sleep for N seconds after exiting and restarting the process.
When the process to be monitored exits due to some reason, for example, the process exits due to the end of the life cycle of the process, and the exiting of the process does not affect the normal operation of the system, the daemon determines again that the operation mode of the process to be monitored can be the mode in which the process continues to be kept exiting.
The entire process flow in the embodiment shown in fig. 1 can also be understood in conjunction with fig. 2.
In this embodiment, a daemon process in the network operating system may obtain a target monitoring message sent by the kernel, where the message may indicate an operating state of a process to be monitored, that is, the process to be monitored is in a start state or an exit state. If the target monitoring message indicates that the process to be monitored is quitted, the daemon process determines the running mode of the process to be monitored and controls the process to be monitored according to the running mode.
In the method, the kernel can monitor the running state of the process to be monitored in the network operating system in real time and notify the daemon of the monitoring message in real time, so that the daemon can also know the running state of the process to be monitored in real time, and further control the running mode of the process to be monitored according to the message, thereby improving the instantaneity of the control of the process to be monitored. Meanwhile, compared with the method that the daemon process monitors the running state of the process in a polling mode, the daemon process directly monitors the running state of the process according to the monitoring message, so that the daemon process can more quickly monitor the exit of the process, and the delay of exit judgment of the process is reduced. Compared with a polling monitoring mode, the method adopting the message receiving mode can also save the system resources of the network operating system.
In the embodiment shown in fig. 1, it is mentioned that, according to different reasons for exiting the process to be monitored, the daemon process determines the running mode of the process to be monitored again differently, for example, the daemon process may be controlled to restart or continue to maintain the exiting state. Optionally, the daemon process may determine the exit reason of the process to be monitored by means of the exit type identifier in the target monitoring message, and the exit reason may include, for example, an abnormal exit and an exit due to the end of the life cycle.
In one case, if the process to be monitored is exited and the target monitoring message includes the preset exit type identifier, it indicates that the process to be monitored is exited by the preset reason, and the process exit caused by the preset reason does not affect the normal operation of the system, so the daemon process can continue to control the process to be monitored to maintain the exit state. Alternatively, the predetermined reason may be an exit due to the end of the life cycle of the process. At this time, since the life cycle of the process to be monitored is already finished, the daemon process does not need to monitor the process any more, and optionally, the daemon process may delete the process data corresponding to the process to be monitored from the monitoring linked list. Optionally, the monitoring linked list is established when the process to be monitored is started for the first time. And the process data corresponding to the process to be monitored is used for reflecting the starting and stopping state of the process to be monitored in a preset time period.
In the whole life cycle of the process to be monitored, if the process to be monitored may have at least one abnormal exit and restart, the process to be monitored may have multiple starts and exits in the whole life cycle, optionally, the process data may include, for example, time for each start or exit of the process to be monitored in the whole life cycle, time interval between adjacent starts or exits, normal operation time of the process to be monitored, and the like, and the content of the process data may also refer to the related description in the following embodiments.
In another case, if the process to be monitored is exited and the target monitoring message includes the non-preset exit type identifier, which indicates that the process to be monitored is exited by a non-preset reason, and the process exit caused by the non-preset reason generally affects normal operation of the system, the daemon process may redetermine the operation mode of the process to be monitored, that is, determine the restart mode of the process to be monitored. Alternatively, the non-preset reason may be an abnormal exit of the process.
Optionally, the target monitoring message may further include a name identifier of the process to be monitored, and for the process to be monitored that exits for a non-preset reason, the daemon process may further determine, according to the name identifier in the target monitoring message, a restart mode corresponding to the name identifier. For example, for different processes to be monitored, the daemon process can control the daemon process to sleep for different durations and restart the daemon process after exiting, that is, individualization of a restart mode is realized. Due to different sleeping time lengths, the daemon process is prevented from simultaneously controlling the restart of a plurality of quitted processes to be monitored, and the processing pressure of the daemon process is reduced.
In the above process, for the process to be monitored that exits with different reasons, the daemon process may determine different operation modes suitable for the process to be monitored, for example, control the daemon process to restart or control the daemon process to continue to maintain an exiting state, and for the process to be monitored that exits with a non-preset reason, different restart strategies may also be set.
If the abnormal quit process to be monitored is not restarted, the normal operation of the whole system can be influenced, namely the daemon process needs to control the abnormal quit process to be monitored to be restarted. In practice, the process to be monitored which is abnormally exited may not be restarted successfully at one time or abnormally exited again after the short restart is successful.
For the above situation, fig. 3 is a flowchart of another process management method according to an embodiment of the present invention. As shown in fig. 3, the method may include the steps of:
s201, acquiring a target monitoring message which is sent by a kernel and indicates the running state of the process to be monitored.
The execution process of step S201 is similar to the corresponding steps in the foregoing embodiment, and reference may be specifically made to the relevant description in the embodiment shown in fig. 1, which is not repeated herein.
S202, if the target monitoring message indicates that the process to be monitored is quitted, determining the quit time of the process to be monitored and the starting time of the process to be monitored when the process to be monitored is started last time from the monitoring linked list.
S203, calculating the time difference between the exit time and the start time.
S204, judging whether the time difference is smaller than a first preset time, if so, executing the step S205 to the step S206, otherwise, executing the step S207.
And S205, updating the restart times of the process to be monitored in the monitoring linked list.
S206, determining the restarting mode of the process to be monitored according to the restarting times of the process to be monitored.
And S207, resetting the restart times of the processes to be monitored in the monitoring linked list.
When the daemon knows that the process to be monitored is exited according to the target monitoring message, the daemon can further inquire process data corresponding to the process to be monitored from the monitoring linked list, and the process data can include the exiting time of the process to be monitored exiting this time and the starting time of the process to be monitored starting last time, so that the time difference between the exiting time and the starting time is calculated.
If the time difference is greater than or equal to the first preset time, optionally, the process to be monitored is exited after running for a long time after the last start, at this time, the process to be monitored can be considered to be normally exited, and the daemon process can clear the restart times of the process to be monitored in the monitoring linked list. The number of restarts is also included in the process data corresponding to the process to be monitored. Optionally, it may also be indicated that the process to be monitored exits due to the end of the life cycle, and the daemon process does not need to monitor the process, so that the daemon process may directly delete the process data corresponding to the process to be monitored from the monitoring linked list.
If the time difference is less than the first preset time, the process to be monitored is indicated to be exited again after running for a short time after the last startup, and the restart of the process to be monitored fails, the daemon process can update the restart times of the process to be monitored in the monitoring linked list, namely the restart times is added by 1, and the restart mode of the process to be monitored is determined according to the updated restart times.
Optionally, determining a restart mode according to the number of restarts in the monitored linked list specifically includes:
if the restart times of the process to be monitored in the monitoring linked list are less than the first preset times, which indicates that the restart failure times of the process to be monitored are less, the restart mode of the daemon process for the process to be monitored is as follows: and controlling the process to be monitored to restart after exiting the second preset time, namely controlling the process to be monitored to sleep for the second preset time length and restart after exiting. Because the process to be monitored is restarted and failed for several times, if the daemon process still immediately controls the process to be monitored to restart, the restart failure is likely to happen, a dormancy time is set for the process to be monitored according to the mode, the process to be monitored is controlled to restart after short dormancy, and the possibility that the process to be monitored is restarted successfully can be improved.
If the restart times of the process to be monitored in the monitoring linked list are greater than or equal to the first preset times, which indicates that the daemon process has failed to restart for multiple times, in order to further improve the possibility of successful restart of the process to be monitored, the daemon process may delete the process data corresponding to the process to be monitored from the monitoring linked list and migrate the process data into the delayed restart linked list. The daemon process can control the process to be monitored in the delayed restart linked list to restart after the process to be monitored exits for a third preset time. Wherein the third preset time period is generally longer than the second preset time period.
Optionally, the process of controlling the process to be monitored in the delayed restart linked list by the daemon process may be:
the daemon process can obtain the exit time of the process from the process data corresponding to the process to be monitored, and if the current time and the exit time are separated by a third preset time length, the restart of the process to be monitored is delayed. If the restart of the process to be monitored in the delayed restart linked list still fails, the daemon process updates the process data corresponding to the process to be monitored in the delayed restart linked list, specifically, updates the delayed restart times in the process data. If the delayed restart times of the process to be monitored are smaller than the second preset times, the daemon process controls the restart of the process to be monitored again after a third preset time interval. Wherein the second preset times is greater than the first preset times.
If the number of delayed restart times is greater than or equal to the second preset number of times, which indicates that the number of delayed restart failure times of the process to be monitored is too large, and the process to be monitored cannot be restarted, the daemon deletes the process data corresponding to the process to be monitored, which cannot be restarted, from the delayed restart linked list, and adds the process data to the restart failure linked list. The daemon process can also further perform corresponding processing on the process to be monitored in the restart failure linked list.
Optionally, in a processing mode, the daemon process may directly control the process to be monitored to maintain the exit state. In order to ensure the normal operation of the network operating system, optionally in a processing mode, the daemon process can also directly control the operation system where the process to be monitored is located to restart; and controlling the restart of the process to be monitored in the restart failure linked list again, and controlling the restart of the running system when the restart failure times reach a third preset time. The daemon process can automatically control the system restart so as to reduce the condition of system paralysis caused by process exit. And the third preset times is greater than the second preset times.
Optionally, for different processes to be monitored, the first preset time length, the second preset time length, and the third preset time length used by the daemon process in the process of controlling the daemon process to restart may be respectively set to different time lengths. And judging whether the process data corresponding to the process to be monitored is migrated to the delayed restart chain table or the restart failure chain table, wherein the first preset times, the second preset times and the third preset times used when the process data corresponding to the process to be monitored is migrated to the delayed restart chain table or the restart failure chain table can also be set to different values, namely different processes to be monitored have different restart strategies.
The above steps can also be understood in connection with the signaling diagram of fig. 4. The specific implementation manner of step S206 can also be understood by referring to fig. 5, which actually shows the restart manner for controlling the process to be monitored according to the delayed restart chain table and the restart failure chain table.
It should be noted that, in practice, there are multiple processes to be monitored, and for some processes to be monitored whose restart is continuously failed, the corresponding process data will be sequentially migrated from the monitoring linked list to the delayed restart linked list and the restart failure linked list; for a part which can be restarted successfully, the corresponding process data can be stored in the monitoring linked list continuously. And the daemon process can independently control the restart of the process to be monitored in the monitoring linked list, the delayed restart linked list and the restart failure linked list, and the control process does not have strict sequence.
In this embodiment, the following restart logic is provided for the restart of the process to be monitored:
in the first stage, in response to the starting of the process to be monitored, the process data corresponding to the process to be monitored is stored in the monitoring linked list. When the process to be monitored abnormally exits, the daemon process can control the restart of the process to be monitored after the process to be monitored exits for a second preset time (namely, sleeps for a period of time), and the restart times of the process to be monitored in the monitoring linked list are updated according to whether the restart is successful or not. If the restart of the process to be monitored fails and the number of times of the restart failure exceeds a first preset number of times, the daemon process can further migrate process data corresponding to the process to be monitored from the monitoring linked list to the delayed restart linked list.
And in the second stage, the daemon process can control the process to be monitored to restart again after the process to be monitored exits for a third preset time length in the process of controlling other processes to be monitored in the monitoring linked list to restart. Because the third preset time length is longer than the second preset time length, the daemon process controls the process to be monitored to carry out delayed restart and updates the delayed restart times of the process to be monitored in the delayed restart linked list according to whether the delayed restart is successful or not. If the number of delayed restart times exceeds a second preset number, the daemon process further migrates the process data corresponding to the process to be monitored from the delayed restart linked list to the restart failure linked list.
And in the third stage, the daemon process can also correspondingly process the process to be monitored in the restart failure linked list. Such as directly controlling the whole system to restart or directly controlling the process to be monitored to maintain the exit state. For example, the process to be monitored in the restart failure linked list is controlled to be restarted, and if the restart failure times of the process to be monitored in the restart failure linked list exceed the preset times, the system is controlled to be restarted.
In this embodiment, the daemon process provides the multi-stage restart-delayed restart logic, which can improve the restart success probability of the process to be monitored. Compared with the problem that the daemon process controls the process to be monitored to be restarted continuously to cause the waste of system computing resources, the restart time of the process to be monitored can be reduced and the waste of the computing resources is reduced by adopting the strategy of delaying the restart.
With reference to the foregoing embodiments, the process data corresponding to the process to be monitored may include: the method comprises the steps of identifying the name of a process to be monitored, a first preset time, a second preset time, a third preset time, starting time and exiting time of the process to be monitored in a preset time period, time difference between adjacent starting time and exiting time, normal operation time of the process to be monitored, restarting times of the process to be monitored, and judging whether first preset times, second preset times and third preset times used when process data corresponding to the process to be monitored are transferred to different linked lists or not. The above-mentioned preset time period may be considered as the whole life cycle of the process.
In the above embodiments, the daemon process can obtain the target monitoring message sent by the kernel, and further control the restart mode of the process to be monitored according to the running state of the process to be monitored reflected by the message. In practice, the kernel can acquire multiple monitoring messages indicating respective running states of different processes running in the network operating system, where the different processes include both a process to be monitored and a process that the daemon process does not need to monitor. Based on this situation, fig. 6 is a flowchart of another process management method according to an embodiment of the present invention. As shown in fig. 6, the method may include the steps of:
s301, responding to the starting of the kernel, analyzing the preset configuration file to obtain an analysis result containing the name identification of the process to be monitored and the running mode of the process to be monitored.
Before process management, a preset configuration file can be manually written. The process to be monitored which needs to be monitored by the daemon process can be written in the configuration file. Optionally, after the process exits, the running mode of the process to be monitored, which is determined again by the daemon process, may also be written into the configuration file. If the running mode of the process to be monitored may specifically include a restart mode, based on the content in the embodiment shown in fig. 3, the daemon process controls that the first preset time, the second preset time, the third preset time, the first preset times, the second preset times, and the third preset times used in the restart process of the process to be monitored may also be written into the configuration file. And different processes to be monitored can be configured with different preset durations and preset times, so that the restarting modes of the processes to be monitored are richer.
Based on the compiled configuration file, in response to the startup of the kernel in the network operating system, the daemon process can analyze the configuration file to obtain the name identifier of the process to be monitored and the respective corresponding operating modes of different processes to be monitored. The two contents may also constitute the analysis result.
S302, a preset interface for receiving the target monitoring message is established.
And S303, sending a monitoring starting message to the kernel according to the preset interface.
S304, receiving monitoring information which is sent by the kernel and indicates the respective running states of different processes according to a preset interface.
S305, according to the analysis result, screening target monitoring messages from the monitoring messages indicating the respective running states of different processes.
Meanwhile, the daemon process can also create a preset interface for receiving the target monitoring message, and sends a monitoring starting message to the kernel by using the preset interface so as to inform the kernel that the daemon process is started, so that the process in the system can be monitored. After receiving the monitoring start message, the kernel can generate and send a monitoring message indicating the respective running states of different processes in the system to the daemon process when the running state of the process to be monitored changes. After the daemon receives the monitoring message indicating the respective running state of the different processes, the target monitoring message can be further screened from the monitoring messages corresponding to the different processes according to whether the process name identifier in the message to be monitored is contained in the process name identifier in the analysis result. Alternatively, the preset interface may be a netlink socket.
It should be noted that step S301 and steps S302 to S303 do not have a strict execution sequence, and the manner provided in this embodiment is only an illustration. And parsing of the configuration file and setting of the preset interface are typically performed after the kernel is initially started.
Optionally, the speed of screening can be further increased by means of a monitoring array. Wherein different processes running in the system all correspond to an element in the monitoring array. If the value of the element is a preset value, the process is indicated as a process to be monitored; and if the value of the element is a non-preset value, the process does not need to be monitored by a daemon process.
After the analysis result is obtained, the daemon process can perform hash calculation on the name identifier of the process to be monitored in the analysis result, the calculated hash value is used as an index of the process to be monitored, the index points to one element in the monitoring array, and the daemon process can set the value of the element as a preset value. The index of the process to be monitored is also used for indicating the position of the element corresponding to the process to be monitored in the monitoring array.
With the running of the processes in the system, the daemon process can also continuously acquire monitoring messages which are sent by the kernel and indicate the running states of the different processes, and the daemon process can respectively calculate hash values of the name identifiers of the different processes so as to obtain indexes of the different processes. If the value of the element pointed by the index of any process in the monitoring data in the different processes is a preset value, the process is indicated to be a process to be monitored, and the monitoring messages reflecting the running state of the process are all target monitoring messages, so that the screening of the target monitoring messages is realized.
S306, if the target monitoring message indicates that the process to be monitored exits, the running mode of the process to be monitored is determined again.
And S307, controlling the running of the process to be monitored according to the running mode.
The execution process of steps S306 to S307 is similar to the corresponding steps in the foregoing embodiment, and reference may be specifically made to the related description in the embodiment shown in fig. 1, which is not repeated herein.
The entire flow in the embodiment shown in fig. 6 can also be understood in conjunction with fig. 7 and 8. In addition, the embodiment shown in fig. 1 can also be understood in conjunction with fig. 8.
In this embodiment, after the kernel is started, the daemon process may obtain the process to be monitored by parsing the configuration file, and screen out a target monitoring message corresponding to the process to be monitored from monitoring messages indicating the operating states of different processes sent by the kernel, thereby further controlling the operating mode of the process to be monitored. The daemon process can realize the control of the process without modifying the code of the process to be monitored, so that the realization of the process control is simpler. In addition, a monitoring array is introduced to improve the screening efficiency of the target monitoring message.
Optionally, in the above embodiments, when the process to be monitored exits, the daemon process controls a restart process of the process to be monitored. In the restarting process, along with the continuous failure of restarting the process to be monitored,
the process data corresponding to the process to be monitored may be migrated to the delayed restart linked list or the restart failure linked list. If the process to be monitored is restarted successfully when being restarted at a certain time, the daemon process can receive a target monitoring message which is sent by the kernel and indicates that the process to be monitored is started. At this time, the daemon process may add the process data corresponding to the process to be monitored to the monitoring linked list, and delete the process data corresponding to the process to be monitored in the delayed restart linked list or the restart failure linked list.
Optionally, after the system is started, the daemon process may analyze the preset configuration file and set the preset interface in the manner shown in fig. 8. Then, when the process to be monitored in the system is started for the first time, the daemon process can also receive a target monitoring message which is sent by the kernel and indicates that the process to be monitored is started. At this time, the daemon process may also add the process data corresponding to the process to be monitored to the monitoring linked list. In this case, as the process to be monitored continuously runs, the restart times in the corresponding process data are gradually accumulated, and the process data recorded in the monitoring linked list is continuously updated, so that the process data corresponding to the process to be monitored may also be migrated to the delayed restart linked list or the restart failure linked list. That is, for the started process to be monitored, the daemon process does not need to control the running mode of the started process, but the daemon process needs to update the corresponding process data in real time. This part of the content can be combined
The process management device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art will appreciate that each of these devices may be constructed using commercially available hardware components and configured through the steps taught in this disclosure.
Fig. 9 is a schematic structural diagram of a process management device according to an embodiment of the present invention, and as shown in fig. 9, the device may include:
the acquiring module 11 is configured to acquire a target monitoring message that indicates an operating state of a process to be monitored and is sent by a kernel.
The determining module 12 is configured to re-determine the running mode of the process to be monitored if the target monitoring message indicates that the process to be monitored has exited.
And the control module 13 is configured to control the operation of the process to be monitored according to the operation mode.
The target monitoring message comprises a netlink message, and the process to be monitored comprises a user process and/or a kernel process.
Optionally, the determining module 12 is configured to control the process to be monitored to maintain an exit state if the process to be monitored exits and the target monitoring message includes a preset exit type identifier;
and deleting process data corresponding to the process to be monitored from a monitoring linked list, wherein the process data reflects the starting and stopping states of the process to be monitored in a preset time period.
Optionally, the determining module 12 is configured to determine a restart mode of the process to be monitored, if the process to be monitored exits and the target monitoring message includes a non-preset exit type identifier.
Optionally, the determining module 12 is specifically configured to: and determining a restarting mode corresponding to the process to be monitored according to the name identifier of the process to be monitored in the target monitoring message.
Optionally, the determining module 12 is configured to determine, if the target monitoring message indicates that the process to be monitored has exited, exit time of the process to be monitored and start time of the process to be monitored when the process to be monitored is started last time from a monitoring linked list, where the monitoring linked list includes process data that reflects a start-stop state of the process to be monitored within a preset time period;
if the time difference between the exit time and the start time is less than a first preset time, updating the restart times of the process to be monitored in the monitoring linked list;
and determining the restarting mode of the process to be monitored according to the restarting times of the process to be monitored.
Optionally, the determining module 12 is specifically configured to: and if the restart times are less than the first preset times, controlling the process to be monitored to restart after exiting the second preset time.
Optionally, the determining module 12 is specifically configured to: and if the restart times are greater than or equal to a first preset time, deleting the process data corresponding to the process to be monitored from the monitoring linked list and storing the process data in the delayed restart linked list.
Optionally, the control module 13 is further configured to control the process to be monitored in the delayed restart chain table to restart after exiting for a third preset time.
The determining module 12 is configured to update the number of times of the delayed restart of the process to be monitored in the delayed restart linked list if the restart of the process to be monitored in the delayed restart linked list fails;
and if the delayed restart times are greater than or equal to second preset times, adding the process data corresponding to the process to be monitored in the delayed restart linked list into a restart failure linked list, wherein the second preset times are greater than the first preset times.
Optionally, the control module 13 is further configured to control a process to be monitored in the restart failure linked list to maintain an exit state; or controlling the running system where the process to be monitored is located to restart.
Optionally, the apparatus further comprises: and the analysis module 14 is configured to analyze a preset configuration file in response to the start of the kernel, so as to obtain an analysis result including the name identifier of the process to be monitored and the operation mode of the process to be monitored.
The obtaining module 11 is specifically configured to: receiving monitoring information which is sent by the kernel and indicates the respective running states of different processes; and screening the target monitoring message from the monitoring messages indicating the respective running states of the different processes according to the analysis result.
Optionally, the apparatus further comprises: a calculation module 15 and a setting module 16.
The calculation module 15 is configured to perform hash calculation on the name identifier of the process to be monitored included in the analysis result, so as to use the calculation result as an index of the process to be monitored.
The setting module 16 is configured to set an element pointed by the index of the process to be monitored in the monitoring array to a preset value.
The obtaining module 11 is specifically configured to perform hash calculation on the respective name identifiers of the different processes, so as to use a calculation result as respective indexes of the different processes; and if the element in the monitoring array pointed by the index of any process in the different processes is a preset value, determining that the monitoring message indicating the row state of any process is the target monitoring message.
Optionally, the apparatus further comprises: a creation module 17 and a sending module 18.
The creating module 17 is configured to create a preset interface for receiving the target monitoring message.
The sending module 18 is configured to send a monitoring start message to the kernel according to the preset interface, so that the kernel sends the monitoring message indicating the respective operating states of the different processes in response to receiving the monitoring start message.
Optionally, the determining module 12 is further configured to add, if the target monitoring message indicates that the process to be monitored is started, process data corresponding to the process to be monitored to a monitoring chain table, where the process data reflects a start-stop state of the process to be monitored within a preset time period.
The apparatus shown in fig. 9 may perform the method of the embodiment shown in fig. 1 to 8, and reference may be made to the related description of the embodiment shown in fig. 1 to 8 for a part not described in detail in this embodiment. The implementation process and technical effect of the technical solution refer to the descriptions in the embodiments shown in fig. 1 to fig. 8, and are not described herein again.
Fig. 10 is a schematic structural diagram of another process management device according to an embodiment of the present invention, and as shown in fig. 10, the device may include: a processor 21 and a memory 22. Wherein, the memory 22 is used for storing a program for supporting the electronic device to execute the process management method provided in the embodiments shown in fig. 1 to fig. 8, and the processor 21 is configured to execute the program stored in the memory 22.
The program comprises one or more computer instructions which, when executed by the processor 21, are capable of performing the steps of:
acquiring a target monitoring message which is sent by a kernel and indicates the running state of a process to be monitored;
if the target monitoring message indicates that the process to be monitored is quitted, the running mode of the process to be monitored is determined again;
and controlling the running of the process to be monitored according to the running mode.
Optionally, the processor 21 is further configured to perform all or part of the steps in the embodiments shown in fig. 1 to 8.
The electronic device may further include a communication interface 23, which is used for the electronic device to communicate with other devices or a communication network.
In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions for the electronic device, which includes a program for executing the process management method in the embodiments shown in fig. 1 to 8.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (12)

1. A process management method is applied to a daemon process, and comprises the following steps:
acquiring a target monitoring message which is sent by a kernel and indicates the running state of a process to be monitored;
if the target monitoring message indicates that the process to be monitored is quitted, the running mode of the process to be monitored is determined again;
and controlling the running of the process to be monitored according to the running mode.
2. The method of claim 1, wherein the re-determining the operation mode of the process to be monitored if the target monitoring message indicates that the process to be monitored has exited comprises:
if the process to be monitored is exited and the target monitoring message contains a preset exit type identifier, controlling the process to be monitored to maintain an exit state;
and deleting process data corresponding to the process to be monitored from a monitoring linked list, wherein the process data reflects the starting and stopping states of the process to be monitored in a preset time period.
3. The method of claim 1, wherein the re-determining the operation mode of the process to be monitored if the target monitoring message indicates that the process to be monitored has exited comprises:
and if the process to be monitored is exited and the target monitoring message contains a non-preset exit type identifier, determining a restart mode of the process to be monitored.
4. The method of claim 1, wherein the re-determining the operation mode of the process to be monitored if the target monitoring message indicates that the process to be monitored has exited comprises:
if the target monitoring message indicates that the process to be monitored is exited, determining the exiting time of the process to be monitored and the starting time of the process to be monitored when the process to be monitored is started last time from a monitoring linked list, wherein the monitoring linked list comprises process data reflecting the starting and stopping states of the process to be monitored in a preset time period;
if the time difference between the exit time and the start time is less than a first preset time, updating the restart times of the process to be monitored in the monitoring linked list;
and determining the restarting mode of the process to be monitored according to the restarting times of the process to be monitored.
5. The method according to claim 4, wherein the determining the restart mode of the process to be monitored according to the restart times of the process to be monitored comprises:
and if the restart times are greater than or equal to a first preset time, deleting the process data corresponding to the process to be monitored from the monitoring linked list and storing the process data in the delayed restart linked list.
6. The method of claim 5, further comprising:
controlling the process to be monitored in the delayed restart linked list to restart after exiting for a third preset time;
if the process to be monitored in the delayed restart linked list fails to restart, updating the delayed restart times of the process to be monitored in the delayed restart linked list;
and if the delayed restart times are greater than or equal to second preset times, adding the process data corresponding to the process to be monitored in the delayed restart linked list into a restart failure linked list, wherein the second preset times are greater than the first preset times.
7. The method of claim 1, further comprising:
responding to the starting of the kernel, analyzing a preset configuration file to obtain an analysis result containing the name identification of the process to be monitored and the running mode of the process to be monitored;
the acquiring of the target monitoring message which is sent by the kernel and indicates the running state of the process to be monitored comprises the following steps:
receiving monitoring information which is sent by the kernel and indicates the respective running states of different processes;
and screening the target monitoring message from the monitoring messages indicating the respective running states of the different processes according to the analysis result.
8. The method of claim 7, further comprising:
performing hash calculation on the name identification of the process to be monitored contained in the analysis result so as to take the calculation result as an index of the process to be monitored;
setting an element pointed by the index of the process to be monitored in the monitoring array as a preset value;
the screening the target monitoring message from the monitoring messages indicating the respective operation states of the different processes according to the analysis result includes:
performing hash calculation on the respective name identifiers of the different processes to take a calculation result as respective indexes of the different processes;
and if the element in the monitoring array pointed by the index of any process in the different processes is a preset value, determining that the monitoring message indicating the row state of any process is the target monitoring message.
9. The method of claim 7, wherein after parsing the preset configuration file, the method further comprises:
creating a preset interface for receiving the target monitoring message;
and sending a monitoring starting message to the kernel according to the preset interface so that the kernel responds to the receiving of the monitoring starting message and sends the monitoring message indicating the respective running states of different processes.
10. An electronic device, comprising:
the acquisition module is used for acquiring a target monitoring message which is sent by a kernel and indicates the running state of a process to be monitored;
the determining module is used for re-determining the running mode of the process to be monitored if the target monitoring message indicates that the process to be monitored is quitted;
and the control module is used for controlling the running of the process to be monitored according to the running mode.
11. An electronic device, comprising: a memory, a processor; wherein the memory has stored thereon executable code which, when executed by the processor, causes the processor to perform the process management method of any of claims 1 to 9.
12. A non-transitory machine-readable storage medium having stored thereon executable code, which when executed by a processor of an electronic device, causes the processor to perform the process management method of any of claims 1 to 9.
CN202111608525.XA 2021-12-22 2021-12-22 Process management method, apparatus and storage medium Pending CN114461486A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111608525.XA CN114461486A (en) 2021-12-22 2021-12-22 Process management method, apparatus and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111608525.XA CN114461486A (en) 2021-12-22 2021-12-22 Process management method, apparatus and storage medium

Publications (1)

Publication Number Publication Date
CN114461486A true CN114461486A (en) 2022-05-10

Family

ID=81407334

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111608525.XA Pending CN114461486A (en) 2021-12-22 2021-12-22 Process management method, apparatus and storage medium

Country Status (1)

Country Link
CN (1) CN114461486A (en)

Similar Documents

Publication Publication Date Title
CN108430116B (en) Disconnected network reconnection method, medium, device and computing equipment
US10871985B2 (en) Displaying media files between changes in states of an application client
CN111324423B (en) Method and device for monitoring processes in container, storage medium and computer equipment
CN107491346B (en) Application task processing method, device and system
CN102999387B (en) Process running gear and method
WO2018019242A1 (en) Self-recovery method and self-recovery system for web server
KR20200078328A (en) Systems and methods of monitoring software application processes
CN112732674B (en) Cloud platform service management method, device, equipment and readable storage medium
JP2011013764A (en) Method, system and program for managing power consumption
CN112099825B (en) Method, device, equipment and storage medium for upgrading component
CN115964153A (en) Asynchronous task processing method, device, equipment and storage medium
CN114640709A (en) Edge node processing method, device and medium
CN111277373A (en) Server switching control method, terminal and storage medium
JP2011070364A (en) Operation management server, roll back execution method, and roll back execution program
CN114461486A (en) Process management method, apparatus and storage medium
CN111506388A (en) Container performance detection method, container management platform and computer storage medium
CN105930215A (en) Control method and control device for mobile terminal
CN112015525A (en) Task process blocking management method
US20090083747A1 (en) Method for managing application programs by utilizing redundancy and load balance
EP3929737A1 (en) Application state control method apparatus, and terminal and computer-readable storage medium
CN114090198A (en) Distributed task scheduling method and device, electronic equipment and storage medium
CN114090270A (en) Thread management method and device, electronic equipment and computer readable storage medium
JP2005267434A (en) Application monitoring device, its program, and its recording medium
CN111400094A (en) Method, device, equipment and medium for restoring factory settings of server system
CN111625420B (en) Distributed training task processing method, device, equipment and storage medium

Legal Events

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